replace formatting with AppleScript in Pages?

A user named SGill offered a clever Applescript to change the highlighting of a searched-for word. I would like to be able to search for a given font attribute—bold, italic, roman—and change it to another. This was possible in Pages 09 using the find/replace feature, but that capability has been missing since Page 09. Does anyone have a sutiable AppleScript script that will address this lacuna?

iMac, macOS High Sierra (10.13.4)

Posted on Mar 30, 2018 1:30 PM

Reply

Similar questions

4 replies

Mar 30, 2018 7:00 PM in response to PeterBreis0807

The problem is that Page '09 is like a decaying isotope: getting weaker all the time. Right now, some features don;t work. I'm told that, as a 32 bit app, it soon won;t work at all. Even though Pages is much less robust than Word, I still prefer it. If only they could add back a few features—more robust search and replace, user conveniences like non-contiguous & columnar search, more robust typographic and image resources, printing comments and maybe printing selected text, and, finally, mail merge: wow! I think Pages 09 had all, or almost all, those features. In any event, being able to search for and replace formatting is a big deal for my needs.

Mar 30, 2018 8:36 PM in response to rogerfromnorwalk

The following AppleScript will change the specified font on each word of the first occurrence of the string in the Pages v7.0 document. Since we are simply matching document words to the words in the string, it is a much more difficult problem (at least late at night) to match all occurrences of the provided string, and change these fonts too.


property HNR : "HelveticaNeue-Regular"

property HNI : "HelveticaNeue-Italic"

property HNB : "HelveticaNeue-Bold"


set fontface to HNB


try

set theStr to text returned of (display dialog "Enter your text string: " default answer "" buttons {"Cancel", "OK"} default button "OK")

on error errmsgnumbererrnbr

return

end try


tell application "Pages"

tell body text of front document

set bodyText to a reference to it

my change_string_font(bodyText, theStr, fontface)

end tell

end tell

return


on change_string_font(btext, aStr, afont)

set strCnt to count of words of aStr

set theCnt to 0


set {TID, AppleScript'stext item delimiters} to {AppleScript'stext item delimiters, space}

set theStrWords to text items of aStr

set AppleScript'stext item delimiters to TID


repeat with aword in words of btext

if theCnt = strCnt then exit repeat

if (theStrWords contains aword) is true then

set font of aword to afont

set theCnt to theCnt + 1

end if

end repeat

return

end change_string_font

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

replace formatting with AppleScript in Pages?

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