AppleScript, Mac Sequoia and Quark Xpress 2026 Issue

Hi, I am new here and have been driven nuts by a script failure. We are still using Quark - the current version - and have a number of scripts to help automate catalogue production. Most of the scripts still function despite having been written (by someone else who is at best unreachable and at worst deceased) 10 years ago. On a Yosemite machine running Quark 2015 this auto caption script is fine if run from the Quark script menu. On Sequoia and Quark 2026 it stalls - no errors, just nothing. I have tried stepping through it in Script Editor and Script Debugger but it crashes out at the same point on the working system as it does the non working system. ( set X to left of bounds as real). I have added beeps and it beeps 1, 2 then 3 times but stops before “beep 4”.

–set CaptionHeight to “”

property DocName : “”

property LabelStyle : false

property pageNo : “”

property X : “”

property Y : “”

tell application “QuarkXPress 2026”

–set QCaptionHeight to “What Height in mm do you want your image captions?”

–set CH to display dialog QCaptionHeight default answer 4.939 with icon note

set CaptionHeight to 4.939 --((text returned of CH))

set DocName to name of document 1

set pageNo to page number of current page of document DocName as string

beep 1

tell document DocName

if not (exists style spec “Caption”) then my makeNewLabelStyles()

–end tell

–tell page pageNo of document DocName

try

set pixThatNeedCaption to object reference of every picture box whose selected is true

on error

display dialog “you need to have at least one picture box, and only picture boxes selected for this script to run”

return

end try

beep 2

repeat with thisPicBox from 1 to (count of pixThatNeedCaption)

tell item thisPicBox of pixThatNeedCaption

–display dialog thisPicBox as string

–set selected to true

–set color to “None”

set X to left of bounds as real

set Y to top of bounds as real

set picWidth to ((right of bounds as real) - X) as real

set picHeight to ((bottom of bounds as real) - Y) as real

beep 3

–set theImageName to my NameFromPath(get file path of image 1 as string)

set t to path of image 1 as string

–tell application “Finder”

set theImageName to name of t

–display dialog theImageName as string

–end tell

beep 4

set selected to false

–set makeTextBoxes to

my makeNewTextBox(X, Y + picHeight, Y + picHeight + CaptionHeight, X + picWidth, (thisPicBox as string) & " p" & pageNo, theImageName)

–set selected to false

end tell

–end if

end repeat

end tell

end tell

on makeNewTextBox(X, Y, H, W, BoxName, caption)

tell application “QuarkXPress 2026”

tell page pageNo of document DocName

make new text box at beginning with properties {vertical justification:bottom justified, name:(“textBox” & BoxName), color:“None”, bounds:{(Y), (X), (H), (W)}}

set selected of text box (“textBox” & BoxName) to true

set story 1 of text box (“textBox” & BoxName) to “NoZero” & caption

end tell

tell document DocName

set style sheet of paragraph 1 of text box (“textBox” & BoxName) to style spec “Caption”

end tell

tell page pageNo of document DocName

try

set every text of story 1 of text box (“textBox” & BoxName) where it is “NoZero000” to “”

set every text of story 1 of text box (“textBox” & BoxName) where it is “NoZero00” to “”

set every text of story 1 of text box (“textBox” & BoxName) where it is “NoZero0” to “”

set every text of story 1 of text box (“textBox” & BoxName) where it is “NoZero” to “”

set every text of story 1 of text box (“textBox” & BoxName) where it is “.tif” to “”

set every text of story 1 of text box (“textBox” & BoxName) where it is “.psd” to “”

set every text of story 1 of text box (“textBox” & BoxName) where it is “.eps” to “”

set every text of story 1 of text box (“textBox” & BoxName) where it is “.jpg” to “”

set every text of story 1 of text box (“textBox” & BoxName) where it is “.jpeg” to “”

end try

–set grouped of group box 1 to true

end tell

end tell

end makeNewTextBox

(*

on NameFromPath(theImagePath)

set theOffset to the offset of “:” in (the reverse of every character of theImagePath) as string

set theImageName to (characters -(theOffset - 1) thru -5 of theImagePath) as string

end NameFromPath

*)

on makeNewLabelStyles()

tell application “QuarkXPress 2026”

tell document DocName

make new character spec at beginning with properties {name:“Caption”, base style:“Normal”}

make new style spec at beginning with properties {name:“Caption”, base style:“Normal”, paragraph attributes:{justification:centered }, character style:“Caption”}

end tell

end tell

end makeNewLabelStyles

It’s good that you’ve narrowed it down to somewhere between beep 3 and 4. Could we know how the script is supposed to function? What is it doing?

Andrew

So the problem is in one of these lines, as far as I understand:

So first, add another beep or dialog, and find out what line exactly is stalling the script.

Second, if the first line is being executed, check what path is actually returned.

Also, is it possible that the problem is in HFS/POSIX paths mixup? I don’t know how Quark handles them and what paths it returns. Maybe it has changed since Quark 2015 (just like it changed in InDesign). Maybe your 2015 script version assumed HFS path, while Quark now returns POSIX, which in turn stalls the script somehow.

It uses the file name to create an image caption. We create catalogues and use it to caption auction lots.

The HFS / POSIX issue could be onto something. Just about all of the old scripts still work but most of them are not grabbing filenames from file paths.

@leo_r is right.

A string doesn’t have a name property. You need the Finder or System Events you retrieve the name of a file or folder by its path depending on whether it is a HFS or POSIX path.

Another complication is that you are in a nested application tell block

tell application  "QuarkXPress 2026"
   -- ...  
   tell document DocName
     -- ...
      tell item thisPicBox of pixThatNeedCaption
1 Like

How might I go about rectifying this issue? I am kind of stabbing in the dark at this as I have had to try and repair a 10 year old script by a deceased author.

This section is where it stalls - I have added beeps after it and they don’t happen.

set t to path of image 1 as string
–tell application “Finder”
set theImageName to name of t
–display dialog theImageName as string
–end tell

I can see what you mean but don’t have a clue how to redefine the name property. Do you think it is it possible for me to repair this section (the script works on Quark 2015) or will this need total revision?

Does it work when you uncomment the tell application "Finder" and end tell lines?

No, it still stops before the four beeps. I think the POSIX / HFS issue might be a possibility but not sure how I would define that in the script.

Please log or display dialog the t variable. Is it a full path? Is it slash separated or colon separated?

I have tried to get it to display a dialog of t and it does nothing. Is there some sort of plug in code to run that I can use to log the entire script to a file? Using script debugger or Script Editor it always crashes out before the section causing trouble. Run through the Quark script menu it will work in QX2015 or just hang in QX2026

I don’t have Quark so I can’t test the script myself.
But if you have Script Debugger you can trace the script line by line and watch all variable values.

By the way please format the code in the initial posting by wrapping it in ``` characters at the beginning and the end of the script.

Testing the formatting out - I can’t edit the original post anymore.

--set CaptionHeight to ""
property DocName : ""
property LabelStyle : false
property pageNo : ""
property X : ""
property Y : ""

tell application "QuarkXPress 2026"
	--set QCaptionHeight to "What Height in mm do you want your image captions?"
	--set CH to display dialog QCaptionHeight default answer 4.939 with icon note
	set CaptionHeight to 4.939 --((text returned of CH))
	set DocName to name of document 1
	set pageNo to page number of current page of document DocName as string
	
	beep 1
	
	
	tell document DocName
		if not (exists style spec "Caption") then my makeNewLabelStyles()
		--end tell
		
		--tell page pageNo of document DocName
		try
			set pixThatNeedCaption to object reference of every picture box whose selected is true
		on error
			display dialog "you need to have at least one picture box, and only picture boxes selected for this script to run"
			return
		end try
		
		beep 2
		
		repeat with thisPicBox from 1 to (count of pixThatNeedCaption)
			tell item thisPicBox of pixThatNeedCaption
				--display dialog thisPicBox as string
				--set selected to true
				--set color to "None"
				set X to left of bounds as real
				set Y to top of bounds as real
				set picWidth to ((right of bounds as real) - X) as real
				set picHeight to ((bottom of bounds as real) - Y) as real
				
				beep 3
				
				--set theImageName to my NameFromPath(get file path of image 1 as string)
				
				set t to POSIX path of image 1 as string
				--display dialog t as string
				tell application "Finder"
					set theImageName to name of t
					display dialog t as string
				end tell
				
				beep 4
				
				set selected to false
				--set makeTextBoxes to 
				my makeNewTextBox(X, Y + picHeight, Y + picHeight + CaptionHeight, X + picWidth, (thisPicBox as string) & " p" & pageNo, theImageName)
				--set selected to false
			end tell
			--end if
		end repeat
	end tell
end tell




on makeNewTextBox(X, Y, H, W, BoxName, caption)
	tell application "QuarkXPress 2026"
		tell page pageNo of document DocName
			make new text box at beginning with properties {vertical justification:bottom justified, name:("textBox" & BoxName), color:"None", bounds:{(X), (Y), (H), (W)}}
			set selected of text box ("textBox" & BoxName) to true
			set story 1 of text box ("textBox" & BoxName) to "NoZero" & caption
		end tell
		tell document DocName
			set style sheet of paragraph 1 of text box ("textBox" & BoxName) to style spec "Caption"
		end tell
		tell page pageNo of document DocName
			try
				set every text of story 1 of text box ("textBox" & BoxName) where it is "NoZero000" to ""
				set every text of story 1 of text box ("textBox" & BoxName) where it is "NoZero00" to ""
				set every text of story 1 of text box ("textBox" & BoxName) where it is "NoZero0" to ""
				set every text of story 1 of text box ("textBox" & BoxName) where it is "NoZero" to ""
				set every text of story 1 of text box ("textBox" & BoxName) where it is ".tif" to ""
				set every text of story 1 of text box ("textBox" & BoxName) where it is ".psd" to ""
				set every text of story 1 of text box ("textBox" & BoxName) where it is ".eps" to ""
				set every text of story 1 of text box ("textBox" & BoxName) where it is ".jpg" to ""
				set every text of story 1 of text box ("textBox" & BoxName) where it is ".jpeg" to ""
			end try
			--set grouped of group box 1 to true
		end tell
	end tell
	
end makeNewTextBox

(*
on NameFromPath(theImagePath)
	set theOffset to the offset of ":" in (the reverse of every character of theImagePath) as string
	set theImageName to (characters -(theOffset - 1) thru -5 of theImagePath) as string
end NameFromPath
*)

on makeNewLabelStyles()
	tell application "QuarkXPress 2026"
		tell document DocName
			make new character spec at beginning with properties {name:"Caption", base style:"Normal"}
			make new style spec at beginning with properties {name:"Caption", base style:"Normal", paragraph attributes:{justification:centered}, character style:"Caption"}
		end tell
	end tell
end makeNewLabelStyles

Thank you for formatting the code. Now the script is readable.
I saw this disabled line above. Most likely the proper command to get the path is file path

Try to uncomment the line and change it to

set theImageName to (file path of image 1) as string

Does the script reach this line? If yes what kind of path is it?