3 Replies Latest reply: Feb 19, 2013 12:04 PM by BioRich
BioRich Level 1 Level 1 (65 points)

Hi folks.

 

How can I format text in a Pages document using AppleScript?  I need to place paragraph styles using the Find dialog box under Advanced, and I don't know how to get in there.  Calling up the Find box always brings it up in the Simple panel. 

 

I want to set the style of all lines with "#####" to "Section" style. 

I then want to get rid of all strings "#####"

 

My file is 102 pages, and I want to automate this process for a client. 

 

Any help appreciated. 

 

Cheers


Mac Pro, Mac OS X (10.6.7), Hypercard UG!
  • Level 8 Level 8 (41,790 points)

    The same question was also asked in an other forum.

    http://macscripter.net/viewtopic.php?id=36417

     

    I posted a script but Nigel Garvey posted this more efficient one :

     

    --{code}

    property styleKeys : {{"#####", "Section"}, {"####", "Class"}, {"###", "Fee"}} -- NB. Style markers arranged longest to shortest.

    on stylise()

       tell application "Pages"

           tell document 1

               set paragraphTexts to paragraphs of body text

               repeat with p from (count paragraphTexts) to 1 by -1

                   set paraText to item p of paragraphTexts

                   repeat with k from 1 to (count styleKeys)

                       set {marker, styleName} to item k of styleKeys

                       if (paraText begins with marker) then

                           set paragraph p of body text to text ((count marker) + 1) thru -1 of paraText

                           set paragraph style of paragraph p of body text to paragraph style styleName

                           exit repeat

                       end if

                   end repeat

               end repeat

           end tell

       end tell

    end stylise

     

    stylise()

    --{code}

     

    Yvan KOENIG (VALLAURIS, France) samedi 2 juillet 2011 22:37:50

    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8


    Please : Search for questions similar to your own before submitting them to the community

     

    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • 101010=42 Level 1 Level 1 (0 points)

    Great solution for *paragraph* formatting, but is there a way to do this for markers inside paragraphs, somewhat on the lines of Markdown? There are ways to use Markdown via the Services menu, true, but those only get RTF results, not character styles in Pages.

  • BioRich Level 1 Level 1 (65 points)

    Hi there. 

     

    Sorry Koenig, I didn't see your post.  I used such a solution and it worked fine for paragraphs.  As for marking up lengths of characters, I'd probably go to RTF then open the file in Pages afterwards, then script replacing styles with Pages styles.  I've not done this, but that would be my approach. 

     

    Cheers