Hello,
I’ve found somewhere in this forum a script to find and replace some text with Applescript.
This script is working perfect, except for the ones that have a different style of text.
For example, if the first word in the document is bold, everything went bold after running the script.
This problem is not only with this kind of style, but also when I use a bullet list in the document.
The current state of the script is displayed at the bottom of this post.
My question is if anyone has a answer for me what I can use to change the script so that it will work like expected.
If anyone has another script that wil work the same way, but not having this problem it is also good.
This is the current state of the script:
global editedText
set before to "apple"
set after to "google"
tell application "Pages"
tell document 1
set BodyText to body text
end tell
end tell
my findAndReplace2(before, after, BodyText)
tell application "Pages"
tell document 1
set body text to editedText
end tell
end tell
on findAndReplace2(toFind, toReplace, theText)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to toFind
set textItems to theText's text items
set AppleScript's text item delimiters to toReplace
tell textItems to set editedText to beginning & toReplace & rest
set AppleScript's text item delimiters to astid
return editedText
end findAndReplace2