applescriptdetectiwork

Applescript: Detect double instances


Here's how a text document in Apple Pages might be structured:

CHARACTER #1: Dialogue

CHARACTER #2: Dialogue

CHARACTER #1: Dialogue

Action description.

CHARACTER #1: Dialogue

My question: Using Applescript, is there a way to detect that the last two dialogue entries stem from the same character, even though there is an action description in between?

CHARACTER names are defined by a paragraph style and always appear in ALL CAPS.

Many thanks for your time!


Solution

  • Disappointingly, the more recent versions of Pages (like 5.5.2, which I have right now) are very limited in AppleScript support. One should be able to access specific properties of paragraphs, including paragraph style (this seemed to be possible in past versions, 5-6 yrs ago), but this is not possible. You'd be better off exporting as an rtf (for example) and using a more complete script-able app -- but guess what? Pages doesn't even support exporting to RTF. A quick bit of advice: If you do end up exporting as Word document, use the older "doc" version instead of the "docx" (under 'Advanced' setting in export), or at least test between them. docx can kill screenplay-formatted documents (which you seem to be working with).

    I'd also suggest that you be more specific with your question, like what the style consists of, and any code you've actually tried (which is considered basic form here on StackOverflow).