Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

KenLind

macrumors newbie
Original poster
Aug 27, 2022
3
0
Nevada
I have some very long documents that is written with several font sizes intermingled throughout the text. For example some text in 14 pt and some text in 12 pt. How can I change one of the sizes without changing the other? For example suppose I want to change the 12 pt text to 14 pt and the 14 pt text to 16 pt? I have written the following AppleScript but I cannot get it to work. Whatever I do seems to error and when I change it to avoid that error I get another until it goes in circles:

```
tell application "Pages"
activate
set theDoc to the front document
tell theDoc
set bodyText to body text
repeat with i from 1 to count of paragraphs of bodyText
set thePara to paragraph i of bodyText
tell thePara
set paraText to its text
if paraText ≠ "" then -- Ensure paragraph has content
if size of its style is 12 then
set size of its style to 14
else if size of its style is 14 then
set size of its style to 16
end if
end if
end tell
end repeat
end tell
end tell
```

Any suggestions on how to accomplish what I am trying to do will be appreciated... Thanx!
 

Slartibart

macrumors 68040
Aug 19, 2020
3,044
2,758
Assuming there are no appropriate character or paragraph styles defines in these documents - you can try to select on character level. I am currently away from my Mac, but for quick testing e.g.:
tell application "Pages" to select (every character of body text of front document whose 12pt is true)
should select all 12pt characters in the current active Pages document (?) - I know it works for bold, italics, etc.
 

KenLind

macrumors newbie
Original poster
Aug 27, 2022
3
0
Nevada
Thanx Slartbart, I tried that. When I do I get an error message that says 'can't get style of [string of letters]'. Here's the code I tried:

```
tell application "Pages"
activate
set theDoc to the front document
tell theDoc
set bodyText to body text
repeat with i from 1 to count of paragraphs of bodyText
set thePara to paragraph i of bodyText
if (count of characters of thePara) > 0 then -- Ensure paragraph has content
set currentSize to size of style of characters 1 thru -1 of thePara
if currentSize is 12 then
set size of style of characters 1 thru -1 of thePara to 14
else if currentSize is 14 then
set size of style of characters 1 thru -1 of thePara to 16
end if
end if
end repeat
end tell
end tell
```
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.