Mavericks Broke Scripting of QuarkXPress

OSX: 10.9
QuarkXPress: 9.5

I have a script that loads a Quark file (the template) and replaces some text and images in the template and saves it is a pdf.

The script was working fine in OSX 10.8. After upgrading to 10.9 Mavericks, the script errors on several points in the script with the following code:

object reference of every generic box whose class is picture box

The error message is as follows:

error “QuarkXPress got an error: Can’t get object reference of every generic box of page 1 of document 1 whose class = picture box.” number -1728 from object reference of every generic box of page 1 of document 1 whose class = picture box

The following is a section of code from which the above line of errant code was taken:

		tell document 1 of application "QuarkXPress"
			tell page 1
				set BoxList to (object reference of every generic box whose class is picture box)
				repeat with MyBox in BoxList
					set BoxIndex to get (index of MyBox)
					set ImageList to (object reference of every image in MyBox)
					repeat with MyImage in ImageList
						set fpath to get (file path of MyImage) as string
						set ImageIndex to get (index of MyImage)
						if fpath is resourcespath & "img_map.jpg" then
							set image ImageIndex of MyBox to file (mappath & ThisStore & ".bmp")
							set bounds of MyImage to proportional fit
						end if
					end repeat
				end repeat
			end tell
		end tell

Again, this was working in 10.8 and still works for a coworker running 10.7.x.

I am not sure how to fix this error. Any help would be greatly appreciated.


I never use generic box but what works for me is addressing the picture boxes immediately (from quark 3 to 9) instead of addressing every box and using a using a filter.

object reference of every picture box

Edit: Maybe I was unclear but that solved the problem on my machine.

The original code seems to be too “heavy”. Isn’t there only 1 picture per picture box? Why do you have to cycle through the indices of several pictures? :confused:

DJ: Thanks DJ! That did the trick. However, now I have a different error I need examine. May be back with another question.

CMYS: Is there a limit of one picture per box in QuarkXPress? I don’t know. I am not a Quark user and this is my first and only AppleScript. I usually do web and SQL Server programming.

I would certainly like to streamline the script if possible. It replaces many elements in the template and is long running when producing approximately 150 pdf documents. However, I would like to keep the code flexible for easy reuse on the next template file produced by the artists.

Thanks for the comment. I will look into this further.


Do the QXP documents have several pages or not? Do the script only acts on page 1 of the docs? Are the projects multiple layouts?

The QXP is a 2 page document (a two-sided advertising flyer).

Elements are replaced on both pages but mostly on the second page.

Not sure of the exact meaning of the term layout regarding Quark, but the next template would be a separate QXP file. The new file would be somewhat similar to the first in what needed to be changed. I would start with a copy of my current code to produce a separate script.

I have an internal web page that allows the user to generate the data needed into text files. The script reads the text files containing the document recipients and the elements for that document. The script then loads the QXP template, replaces the elements, writes to pdf, closes the QXP and repeats for all document recipients. It should generally produce about 150 documents.

I am very new to AppleScript and QuarkXPress, and I have found it very difficult at times. It seems to follow a different paradigm for addressing objects. I kept looking for a way in Quark to give the page elements a name that I could then use in the script to address that object (image or text). I couldn’t find the index for the object in Quark either. Finding all the objects of a type and cycling through them by index was the only solution I found. To find an image I need to replace, I cycle through all the picture boxes on a page looking for an element with a specific file path. This does not seem very efficient. Am I missing something? Is there a better way? Any help is much appreciated.


Remember that QuarkXPress was market leader for DTP software as it was the role model for scriptability with AppleScript. Nothing has changed since in QuarkXPress, while AppleScript has changed in 20 years. The drawback is that because of different AppleScript versions you’re not able to run 20 year old AppleScripts on modern machines, while it’s not Quark’s fault.

It maybe doesn’t help you much but gives you some information why it feels a bit odd compared to a relative new DTP application like InDesign.

You can actually name boxes in Quark for an easier use (targetting) in AS later.
But this is not doable within QuarkXPress so you’d have to first run a script that’d name the different boxes. If you work on a template, then it should stick and be targetable any time you open it.

On Quark’s forums, Scripting_Ace posted a code to name the current box:

tell application "QuarkXPress"
	tell document 1
			set DefaultAnswer to ""
			if name of current box is not "" then
				set NameString to "This box is named " & return & return & "\"" & name of current box & "\""
				set TheButtons to {"Cancel", "Change", "Keep"}
				set DefaultAnswer to name of current box
				set Q1 to display dialog NameString buttons TheButtons default button 3 with icon 1
				set NameString to "This box has no name."
				set TheButtons to {"Cancel", "Name"}
				set Q1 to display dialog NameString buttons TheButtons default button 2 with icon 1
			end if
			if button returned of Q1 is item 2 of TheButtons then
				tell me to NameThatBox(DefaultAnswer)
			end if
		on error errMsg number errNum
			if errNum is not -128 then
				display dialog errMsg & " " & errNum
				display dialog "Select a box." with icon 2
			end if
		end try
	end tell
end tell
on NameThatBox(DefaultAnswer)
	tell application "QuarkXPress"
		tell document 1
			if DefaultAnswer = "" then
				if box type of current box is picture box type then
					set DefaultAnswer to "pic_"
				else if box type of current box is text box type then
					set DefaultAnswer to "txt_"
				else if box type of current box is line box type then
					set DefaultAnswer to "line_"
				else if box type of current box is group box type then
					set DefaultAnswer to "grp_"
					set DefaultAnswer to "box_"
				end if
			end if
			set Qstring to "Rename this box "
			set TheAnswer to display dialog Qstring default answer DefaultAnswer
			set BoxName to text returned of TheAnswer
			set name of current box to BoxName as text
		end tell
	end tell
end NameThatBox

Then yes a picture box in QuarkXPress only has 1 picture. It’s accessed by image 1 of [picture box] and its path is simply file path of image 1 of [picture box].


DJ: Thanks for the info.

CYMS: Thanks for the info about naming and addressing the single image of a picture box. The script looks interesting and could potentially save me a lot of time. I didn’t realize that a name assigned to a box by AppleScript would save in the QXP file since Quark doesn’t really seem to support naming the boxes. Anyway, I will definitely give that script a try. Thanks again.