Find and Replace, quark/xcatalog

Hello,

I’m working on a script to automate find/replace in quark documents. I’m new to both quark and applescript but have managed to patch something together mostly from searching through this forum.

The problem seems to be that the quark documents have numerous links that were made using xcatalog. It looks like my script is descending into the links or something. I’m getting weird stuff like “blah300UF10XRe” where “blah” is the replacement word. It works fine on documents that don’t use xcatalog. Also, if I select an area and clear all links it will work fine but the links need to stay intact.

I’m using quarkexpress 6.5 and xcatalog 6.2.1

Any help is appreciated. Thanks

Here is my script:


--open list of words to find
set findFile to (choose file with prompt "Select find file: ")
open for access findFile
set findlist to (read findFile)
close access findFile
set flist to (every paragraph of findlist)

--open list of replacement words
set replaceFile to (choose file with prompt "Select replace file: ")
open for access replaceFile
set replacelist to (read replaceFile)
close access replaceFile
set rlist to (every paragraph of replacelist)

--choose directory containing quark files
tell application "Finder"
	activate
	set source_folder to choose folder with prompt "Select folder:"
	set source_files to (files of entire contents of source_folder whose file type is "XPRJ")
	set source_files to sort source_files by name
	set source_files to (sort source_files by name) as alias list
end tell

--loop through quark documents
tell application "QuarkXPress"
	activate
	repeat with i from 1 to length of source_files
		set quarkfile to item i of source_files
		open quarkfile as alias use doc prefs yes remap fonts no without reflow
		tell document 1
			set countvar to 1
			--loop through list of words to find 
			repeat until ((countvar) = length of flist)
				set old_word to item (countvar) of flist
				set new_word to item (countvar) of rlist
				
				if old_word is not "" then
					set search_strings to {(old_word)}
					set replace_strings to {(new_word)}
					set myselection to (a reference to text of every story)
					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
					set countvar to countvar + 1
				end if
			end repeat
		end tell
		--close document 1 saving yes
	end repeat
end tell

Model: mac mini
AppleScript: 1.10.7
Browser: Firefox 2.0.0.11
Operating System: Mac OS X (10.4)

if I add a return statement like so:


set mysearch to (a reference to (text of myselection whose contents of it = (old_word)))
return contents of mysearch

I get a long list like this one if I’m searching for the word “Elements”


{"Elements", "Elements", "","", "",
"Underst", "Elements", "", "Elements", "
Worksur", "to", " Managem", "", "ctive El", "pports	", " Cable M", "Products", "", "ve Eleme", "", "ctive El", "", "Elements", "", ""Elements", "", "Elements", "Elements", "Elements", "Elements", "", "Element", "Elements", "e Elemen", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "e Elemen", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "Elements", "e Elemen", "Elements", "Elements", "Elements", "Elements"}

How would I loop through all the contents and only replace the ones that match “Elements”?