You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

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

In Pages Find and Replace, can you specify format you want to use for the replacement?

I want to replace all instances of a word with the same word only bolded and in a different color. This was very simple in MS Word but I am having trouble trying to get it to work in Pages (version 6.3).

MacBook Pro TouchBar and Touch ID, macOS High Sierra (10.13.2)

Posted on Jan 12, 2018 1:48 PM

Reply
52 replies

Jan 13, 2018 6:57 PM in response to MauraMacP

MauraMacP wrote:


I want to replace all instances of a word with the same word only bolded and in a different color. This was very simple in MS Word


Contrary to what you've read here, this is very simple in Pages 6.3 too!


No need to know any AppleScript. You should be up and running in less than a minute.


Just basic copy-paste the script below into Script Editor (in your Applications > Utilities Folder) and make sure Script Editor is already checked at System Preferences > Security & Privacy > Privacy > Accessibility. With your Pages document open click the triangle 'run' button and answer the prompt.


If you need to do this often then you can easily place the script in the script menu or in an Automator Service so that it effectively becomes just another menu choice. You can even attach it to a keyboard shortcut.


If you want a different color or font just change the values between the "" in the first two lines.


SG


set highlightColor to "red"

set highlightFont to "HelveticaNeue-Bold"

set searchWord to text returned of ¬

(display dialog "Highlight what word?" default answer "" buttons {"Cancel", "Continue"} default button "Continue")

tell application "Pages"

tell document 1's body text

try

set color of (words where it is searchWord) to highlightColor

set font of (words where it is searchWord) to highlightFont

end try

end tell

end tell

Jan 13, 2018 7:15 PM in response to SGIII

Thank you SG! 🙂


You will need to adjust that script, it is not** finding instances in Textboxes, Shapes or Objects.


Also I tried this in TextEdit* and it does not find the instances of the word and does not highlight the color.


Peter


* Sorry just reread the script and noticed you specifically cite Pages. Can you change this to be non-specific and target the open App instead? **Also notice that you specify Body Text in the script as well.

Jan 14, 2018 8:20 AM in response to PeterBreis0807

Hi Peter,


The equivalent for TextEdit turns out to be slightly different: text not body text.


SG


set highlightColor to "red"

set highlightFont to "HelveticaNeue-Bold"


set searchWord to text returned of ¬

(display dialog "Highlight what word?" default answer "" buttons {"Cancel", "Continue"} default button "Continue")


tell application "TextEdit"

tell document 1's text

try

set color of (words where it is searchWord) to highlightColor

set font of (words where it is searchWord) to highlightFont

end try

end tell

end tell

Jan 14, 2018 8:26 AM in response to SGIII

Thanks for your work SG


Is it possible to make this script simply address whatever App is open and in the case of Pages Search and Replace all text, not just the body text? And change bold/italic as well which would bring it closer to Pages '09 which can do all the attributes of text not just this, and do it with a simple change of Character Style.


This could be super useful. 🙂


Peter

Jan 14, 2018 9:18 AM in response to PeterBreis0807

It doesn't do everything (I don't have Pages '09 to compare) but this simple script seems to be an efficient way to search and highlight a word in Pages body text, text boxes, and shapes.


SG


property highlightColor : "red"

property highlightFont : "HelveticaNeue-Bold"

set searchWord to text returned of ¬

(display dialog "Highlight what word?" default answer "" buttons {"Cancel", "Continue"} default button "Continue")

tell application "Pages" to my highlightWord(a reference to document 1's body text, searchWord)

tell application "Pages" to repeat with i in document 1's text items

my highlightWord(a reference to i'sobject text, searchWord)

end repeat

tell application "Pages" to repeat with i in document 1's shapes

my highlightWord(a reference to i'sobject text, searchWord)

end repeat

to highlightWord(thePagesObject, searchWord)

tell application "Pages" to tell thePagesObject

set color of (words where it is searchWord) to highlightColor

set font of (words where it is searchWord) to highlightFont

end tell

end highlightWord

Jan 14, 2018 9:50 AM in response to PeterBreis0807

Because the available text attributes are not uniform across apps it's tough to come up with a generalized script that doesn't quickly become unwieldy.


It think it may be possible to specify other text attributes in a script for Pages. But at this point, because of limited scripting skills and thus a need to keep things simple, I will conveniently classify that as a "nice but not necessary" feature.🙂


Meanwhile, there is a simple way to find and highlight a word in the Pages 6.3.


SG

Jan 14, 2018 11:27 AM in response to PeterBreis0807

I like the wisdom and utility of SGIII's script — considering the limitations imposed by Pages v6.3 AppleScript dictionary. It could even set highlightColor via a color chooser.


set highlightColor to (choose color default color {0,0,0})


Should the user change their mind, and wish to undo the document changes, it will be two undo (command+Z) for each changed word.

In Pages Find and Replace, can you specify format you want to use for the replacement?

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