Failed search within Quark 6

i have written a simple script to do some various searched within a selection in Quark 6. Each part of the script seem to work by themselves, but when they are put together I get an error after the first part is complete. If i run the scriot again I get the next section to work OK, but then errors again and so on… untill the search is complete. Any Ideas?

tell application “QuarkXPress”
activate
set mytext to return
set mytab to tab
set mypound to “£”
set myspace to " "
tell document 1
set myselection to selection
tell myselection
set mysearch to a reference to (text of myselection whose contents = “.” & myspace & myspace & myspace)
set contents of mysearch to “.” & tab

		set mysearch2 to a reference to (text of myselection whose contents = myspace & mypound)
		set contents of mysearch2 to mytab & mypound
		
		set mysearch3 to (a reference to (text of myselection whose contents = mytab & myspace))
		set contents of mysearch3 to mytab
		
		set mysearch3 to (a reference to (text of myselection whose contents = mytab & myspace))
		set contents of mysearch3 to mytab
		
		set mysearch3 to (a reference to (text of myselection whose contents = mytab & myspace))
		set contents of mysearch3 to mytab
	end tell
	display dialog "End"
end tell

end tell

You seem to be changing myselection each time. After each search and replace, try resetting myselection to selection. Even better, change the initial myselection to a reference to text of selection.

Jon

hi Jon
Thanks for the pointers, i have done as you said as below, but i get the same problem. i am fairly new to AS, so please be patient with me! i may well be overlooking somthing obvious:-

tell application “QuarkXPress”
activate
set mytext to return
set mytab to tab
set mypound to “£”
set myspace to " "
tell document 1
set myselection to a reference to text of selection
tell myselection
set mysearch to a reference to (text of myselection whose contents = “.” & myspace & myspace & myspace)
set contents of mysearch to “.” & tab
end tell

	set myselection2 to a reference to text of selection
	tell myselection2
		set mysearch2 to a reference to (text of myselection2 whose contents = myspace & mypound)
		set contents of mysearch2 to mytab & mypound
	end tell
	
	set myselection3 to a reference to text of selection
	tell myselection3
		set mysearch3 to (a reference to (text of myselection3 whose contents = mytab & myspace))
		set contents of mysearch3 to mytab
	end tell
	
	set myselection4 to a reference to text of selection
	tell myselection4
		set mysearch4 to (a reference to (text of myselection4 whose contents = mytab & myspace))
		set contents of mysearch4 to mytab
	end tell
	
	set myselection5 to a reference to text of selection
	tell myselection5
		set mysearch5 to (a reference to (text of myselection5 whose contents = mytab & myspace))
		set contents of mysearch5 to mytab
	end tell
	
	display dialog "End"
end tell

end tell

any further suggestions?

Cheers
Roy

I don’t have QXP 6 but in 4.11 this works for me and properly converts all the search strings to the replace strings in a selection:

Jon

Cheers Jon.
This has been a great help. I too can run it perfecrly in XPress 4, but not 5 or 6. I dont know if it a Quark issue, but it seems to be.
Do you know of any reference material (other than the PDF on the Quark CD) relating to sceripting in Quark?

Thanks Again,

Roy

oops

that is a nice clean way to do that
now what if i wanted to search the doc for every word that is “alpha” and replace it with the letter a of the symbol font

and others ie beta, delta, epsilon…zeta, etc.

and while i am at it i would like to apply superior style to every ™ and ®

thanks in advance for any help

OSX 10.3.5 Quark 6.0

UPDATE

set Greeksearch_strings to {“alpha”, “beta”, “delta”, “epsilon”, “gamma”, “kappa”, “lambda”, “mu”, “sigma”, “tau”, “zeta”}
set Greekreplace_strings to {“a”, “b”, “d”, “e”, “g”, “k”, “l”, “m”, “s”, “t”, “z”}

tell application “QuarkXPress”
activate
tell document 1
set myselection to a reference to text of selection
repeat with i from 1 to (count of Greeksearch_strings)
try
set mysearch to (a reference to (text of myselection whose contents of it = (item i of Greeksearch_strings)))
set font of myserch to “symbol”
set contents of mysearch to (item i of Greekreplace_strings)
end try
end repeat
display dialog “End”
end tell
end tell

this script was automatically tagged for
color coded syntax by Script to Markup Code
written by Jonathan Nathan

i came up with this part pased on jonn’s code but basicaly nothing happens in Quark 6.0 any ideas