Apple Script (?) to change font and size within a Pages document

I am a 100% newbie to Apple Script so I am struggling, but I need something that will enable me to change all occurances of specific font and size within a Pages document, to a different font/size.


It is a huge document so I m struggling to do this manually within pages as the occurances are scattered throughout the text and 'contained' in several Text styles


I have tried to following Apple Script...


tell application "Pages"

tell front document

tell body text

set matchingWords to every word where its font is "Cambria" and size is 11

repeat with w in matchingWords

set font of w to "Avenir"

set size of w to 14

end repeat

end tell

display dialog "Font and size replacement complete! All Cambria (size 11) text changed to Avenir (size 14)." buttons {"OK"} default button 1

end tell

end tell


The script runs, with no Error messages.. but the source document is not being changed at all. So I am assuming my code to identify the 'matrching words' is not working.


Does anyone have any pointers or suggestions as to how I can get this to work?


Thanks



iMac 27″ 5K, macOS 13.7

Posted on Oct 10, 2026 4:27 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 10, 2026 9:50 AM

Hey I really appreciate your help, but my code definitely worked changing both the font AND the size.


i don’t really understand AppleScript at all ( as you can probably tell).. the only difference between yours and mine is I have “tell words of (every word….” and you have “tell (every word of….”.. I’ve no idea what difference this makes…


tell application "Pages"

tell body text of front document

tell words of (every word of every paragraph where font contains "cambria" and size is 11)

set size to 14

set font to "Avenir italic"

end tell

end tell

end tell


But hey, it finally works for me so I’m happy.


again i really appreciate the time and effort you’ve spent helping me


thank you.


dont spend any more time on it! lol :-)

11 replies
Question marked as Top-ranking reply

Oct 10, 2026 9:50 AM in response to VikingOSX

Hey I really appreciate your help, but my code definitely worked changing both the font AND the size.


i don’t really understand AppleScript at all ( as you can probably tell).. the only difference between yours and mine is I have “tell words of (every word….” and you have “tell (every word of….”.. I’ve no idea what difference this makes…


tell application "Pages"

tell body text of front document

tell words of (every word of every paragraph where font contains "cambria" and size is 11)

set size to 14

set font to "Avenir italic"

end tell

end tell

end tell


But hey, it finally works for me so I’m happy.


again i really appreciate the time and effort you’ve spent helping me


thank you.


dont spend any more time on it! lol :-)

Oct 10, 2026 7:26 AM in response to J_R_D

I have a revised script that addresses mixed paragraphs of HelveticaNeue and various faces of 11 pt Cambria. It converts only the Cambria paragraphs to 14 pt Avenir. The assumption is the paragraphs are uniformly the Cambria font and not mixed fonts.


If mixed fonts however, and you only want to change the words in the document that are in Cambria, then you will have to change paragraphs to words below and that is a very long running script… depending upon document length.


use scripting additions

set theFont to "Cambria"
set replaceFont to "Avenir"
set fontSize to 14

tell application "Pages Creator Studio"
	activate
	tell body text of front document
		repeat with aword in paragraphs of it
			if (aword's font contains theFont and aword's size is 11) = true then
				set font of aword to replaceFont
				set size of aword to fontSize
			end if
		end repeat
	end tell
end tell
return



Oct 10, 2026 9:09 AM in response to J_R_D

Unfortunately, AppleScript quietly ignores the second part of your syntax "and size is 11" changing only the Cambria to Avenir. I wanted so badly to have this work, but it only changes the font, not the size:

tell application "Pages Creator Studio"
	activate
	tell body text of front document
		tell (every word of every paragraph where font contains "Cambria" and size is 11)
			set its font to "Avenir"
			set its size to 14
		end tell
	end tell
end tell


So now, I am out of ideas. Still looking at it for a solution, but clock hands are moving…

Oct 10, 2026 5:00 AM in response to J_R_D

OK So an update to this.. I have just been playing around with a single word document ("Hello") to try and see if I can get any further. it looks like I need to amend the font name as below. Doing this successfully identifies the word with that font, but I now get an error message saying I cannot change the font.. even if I try to amend to the same font. See screenshot.


Am I trying to do something that isnt actually possible??

Oct 10, 2026 5:37 AM in response to J_R_D

You can change all faces of Cambria in a document (I used respective paragraphs of (regular, italic, and bold italic) to just Avenir Book and the desired point size. It will not however intelligently replace with the corresponding Avenir font face for oblique or medium oblique without being specific in separate if blocks, or referring to a list of font faces and a contains clause to match that font face.


You would still use the "Pages" application name on versions of Pages older than 15.


-- change all body text matching specific font attributes to another font
-- Refer to Font Book for the specific font name

tell application "Pages Creator Studio"
	tell body text of front document
		
		if its font contains "Cambria" and its size is 11 then
			set its font to "Avenir"
			-- set its color to "blue"
			set its size to 14
		end if
		
	end tell
end tell


Tested: Pages v15.4, macOS 27.0.1

Oct 10, 2026 5:49 AM in response to VikingOSX

That worked! Thank you so much. That has saved me so much work


Do you know if there is a way for me to also change it to italics in addition to the font/size?


Actually - That only seems to work if Cambria is the font of the first word in the document. It doesnt work if the text I am looking for is elsewhere in the documemt

Oct 10, 2026 6:40 AM in response to VikingOSX

Yeah, but if the first paragraph is NOT in Cambria, the script doesnt work.


My document is a mixture of fonts, and I only want to change the words that are in Cambria.


Also, The script seems to amend the whole document.. not just the individual words in that font


BTW - I DO appreciate you trying to help me. It is much appreciated.


This is an example of the text I am trying to amend.. only the words highlighted in red would need changing based on their font attributes.


Maybe this is not possible ?


Oct 10, 2026 7:45 AM in response to VikingOSX

I think you might have missed the screenshot I added earlier, the paragraphs ARE mixed fonts. so unfortunately this didn't work either.


HOWEVER, I don't know if you have seen another reply I sent you, but I managed to get this code to do what I needed...



tell application "Pages"

tell body text of front document

set the font of (every word of every paragraph where font contains "cambria" and size is 11) to "Avenir"

end tell

end tell



But if you don't mind, do you think you would be able to help me amending that code to also change the font size in addition to the font name.


I cant just add the line ...


set the size of (every word of every paragraph where font contains "cambria" and size is 11) to "10"


because when it gets to this line of code, the font has already been amended to Avenir from the previous line.


If I changed this line to now read....


set the size of (every word of every paragraph where font contains "avenir" and size is 11) to "10"


I run the risk of changing other text I dont want to.


See I need to amend my code to be somehow similar to yours where the "set font" and "set size" are inside some kind of "if" statement??


Thanks very much



Apple Script (?) to change font and size within a Pages document

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