Pages

Thursday, August 8, 2013

Applescript to change Pages underline to italic

I need to scan 85,000 words in a Pages document and change all underlined words to italic.  I have the following code:

 

tell application "Pages" to tell front document

          repeat with i from 1 to (count every word)

                    tell word i

                              if underline type is in {single underline, double underline} then set properties to {underline type:none, italic:true}

                    end tell

         end repeat

end tell

 

This works great as far as it goes.  The only problem is that this changes only the words in the document, but not the spaces between them.  So it will turn this: (The quick brown fox)  into this: (The_quick_brown_fox).  But what I want is this: (The quick brown fox).

 

So how would this Applescript need to look to change the formatting of the space after the word, as well as the formatting of the word itself?  Or maybe the code should add a delete and space after each changed word?  I'm not sure.

 

Any help is HUGELY appreciated!


View the original article here

0 comments:

Post a Comment