Find & Replace text in QuarkXPress 7.3 Passport from FileMaker Pro 10

I’ve written a few scripts over the years and have read with interest the many solutions people have developed here at MacScripter. However, with all this knowledge I still cannot fathom how to achieve what, to me at least, is a simple task: take a list of search words and replace words from FileMaker, open a Quark doc (again from FM; this I can do) then using QuarkXPress Find & Replace each of these passed lists.

I’ve tried a ‘proper’ AppleScript and even tried cheating with UI scripting. Neither works for me. The latter bring up the Find & Replace floating window and allows me to populate the find and replace text areas, but whenever I try to ‘click checkbox’ or ‘click button’ nothing happens (besides the item in question flickering a change of colour to indicate a mouse click).

Ideally I’d like to use an AppleScript over UI scripting as it would likely be faster and more robust. I’d show you a script I’ve developed, but frankly I doubt anything I’ve cobbled-together would actually help here.

As I’ve said above, I can script FileMaker to gather the criteria for each document which needs to be replaced and I can open the Quark doc from FM (as FM knows where the doc is stored etc.). It’s just the Find & Replace within the document that I cannot achieve.

Any suggestions will be very greatly appreciated!

An example of the UI script I tried (which just teases me by changing the colour of the buttons to simulate a button click):

activate application "QuarkXPress Passport"
tell application "System Events"
	tell process "QuarkXPress"
		click menu item "Find/Change" of menu 1 of menu bar item "Edit" of menu bar 1
		keystroke findText & tab & replaceText & return
		set frontmost to true
		click button 7 of window 1
		click button 4 of window 1
	end tell
end tell

Found this AppleScript in the Quark forums (I’ll be sure to check these in future!) which does exactly what I want and really fast to boot!:

SAndR("2011", "2012")
SAndR("color", "colour")

on SAndR(searchstring, replacestring)
	tell document 1 of application "QuarkXPress Passport"
		-- the try...end try bit means it won't error if it doesn't find any instances of a given searchstring
		try
			set (every text of every story where it is searchstring) to replacestring
		end try
	end tell
end SAndR