Ravi is right - but you won't be able to read XPress Tags within a Quark document. You have to save as text with XPress Tags first, then do the search and replace, then put the text back in.
Have a look at this. I've put in a few explanations but ask if you don't understand!
set my_path to (path to desktop folder from user domain) as string
set export_file to my_path & "ExportedText"
set new_file to my_path & "CleanedText"
--this part saves story 1 as an XPress Tags file, named ExportedText
tell document 1 of application "QuarkXPress"
tell story 1
save it in file export_file as "XPress Tags"
end tell
end tell
--now for the search and replace routines, which run on the exported text file
copy (read file export_file) to the_text
set fileref to open for access new_file with write permission
-- Put the search and replace strings in here. Copy the line and put in as many as you like.
set the_text to replace_chars(the_text, "the text to look for", "the text to replace it with")
-- Now the edited file is saved as "CleanedText"
write the_text starting at eof to fileref
close access fileref
-- Write the edited file back into story 1
tell application "QuarkXPress"
set properties to {import styles:true}
tell document 1
set story 1 to file new_file --re-import the text
end tell
end tell
--now delete the text files, otherwise subsequent runs will add to them!
tell application "Finder"
delete file export_file
delete file new_file
end tell
display dialog "DONE"
-- this routine does the search and replace work for you
on replace_chars(this_text, search_string, replacement_string)
set item_count to 10
repeat until item_count = 1
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set item_count to length of item_list
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
end repeat
return this_text
end replace_chars