Hi, I’m new to Applescript.
Pages 2 lets you change paragraph styles ONLY by clicking a named style in the Styles Drawer OR finding the named style in a dropdown from the Style button. Unfortunately, these lists of named styles are inaccessible for GUI scripting (I’ve tried with both Prefab UI Browser and the Apple UI inspector.)
How do I write a script for changing the paragraph style to a different named style (such as “Normal”)?
Model: PowerBook G4
Browser: Safari 417.8
Operating System: Mac OS X (10.4)
Okay, hey, I’m getting there – I did this:
tell application “Pages”
tell document 1
set newStyle to a reference to paragraph style “Normal”
tell body text
set paragraph style of paragraph 3 to newStyle
This changes the style on Paragraph 3. It works. But how do I change it so that it applies not to Paragraph 3, but to the CURRENT paragraph I’m typing in?
Okay, by changing “paragraph 3” to “last paragraph” I can get 80% of the functionality I need. But sometimes I’m editing in the middle of a document; is there any way to select the CURRENT paragraph rather than the last one?
Scott Lindsey on the applescript mailing list gave me the solution.
tell document 1 of application “Pages”
set theSelection to selection
set paragraph style of theSelection to paragraph style “Normal”