I put together a couple of scripts I found here and elsewhere to make a script that searches every text box of the open xpress document for various stings of text and replaces them with a different string. The script loads the list of changes from a text file. On a G5 iMac using Quark 3.32r5 in classic, the script below works, but runs incredibly slow. I had to put in a dialog showing each change as it processes, the slowness is not due to this dialog. While the “giving up after 1” adds the 1 second per change, it at least lets you know the script is working. Out list of changes is around 150, so the script takes a few minutes to march through the file. Any suggestions on if there is a better way to optimize this script would be appreciated.
set ListFile to (path to home folder) as string
set ListFile to ListFile & “Library:Preferences:changeslist.txt”
tell application “Finder”
set checkForList to (file ListFile) exists
end tell
– above checks to see if there is a file of changes in~/Library/Preferences/changeslist.txt
– changeslist.txt should contain a set of equal sign delimtes changes onec change per line
–Bilbo=Frodo
–Merry=Pippin
–etc
if checkForList is true then
try
set LoadChangesCmd to “cat ~/Library/Preferences/changeslist.txt”
set Changes to (do shell script LoadChangesCmd)
set ChangesList to paragraphs of Changes
set listcount to number of items in ChangesList
repeat with i from 1 to number of items in ChangesList
set ThisChange to item i of ChangesList
set {od, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, “=”}
set ThisChange to (text items of item i of ChangesList)
set AppleScript’s text item delimiters to od
set oldWord to item 1 of ThisChange
set newWord to item 2 of ThisChange
ChangeInQuark(oldWord, newWord, i, listcount)
end repeat
on error errmsg number errNum
display dialog errmsg & return & errNum
end try
else
display alert “There is no list of changes.” message “Place an equal sign delimited list in ~/Library/Preferences/changeslist.txt” as warning
end if
activate me
display dialog “All text has been replaced.” buttons {“Thanks”} default button 1
on ChangeInQuark(old_word, new_word, j, total)
set search_strings to {(old_word)}
set replace_strings to {(new_word)}
tell application "QuarkXPressâ„¢ 3.32r5"
activate
display dialog ((j as string) & " of " & total as string) & return & old_word & " -> " & new_word buttons {"OK"} giving up after 1
try
set pageList to {}
set textboxList to {}
tell document 1
if pageList = {} then
set pageList to index of every page
if class of pageList ≠list then set pageList to {pageList}
end if
set pageCount to count of pageList
repeat with p from 1 to pageCount
tell page (item p of pageList)
if textboxList = {} then
set textboxList to index of every text box
if class of textboxList ≠list then set textboxList to {textboxList}
end if
set textboxCount to count of textboxList
repeat with t from 1 to textboxCount
tell story 1 of text box (item t of textboxList)
set myselection to (a reference to text of selection)
repeat with i from 1 to (count of search_strings)
try
set mysearch to (a reference to (text of myselection whose contents of it = (old_word)))
set contents of mysearch to (new_word)
end try
end repeat
end tell
end repeat
end tell
end repeat
end tell
on error errmsg number errNum
display dialog errmsg & return & errNum
end try
end tell
end ChangeInQuark