Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to AppleScript an Advanced Replace

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!

Posted on Jun 30, 2011 7:08 PM

Reply
3 replies

Jul 2, 2011 1:38 PM in response to BioRich

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 !

How to AppleScript an Advanced Replace

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.