You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript InDesign script doesn't work from script menu

Them variable IDunit in this script, using the script editor, gives me the units inches but when run from the script menu, gives me zinc and if I ask for it as a string, it gives me «constant****zinc» (display dialog). How can I fix this so it works from the script menu?


tell application id "com.adobe.indesign"
	tell active document
		tell view preferences
			set IDunit to horizontal measurement units as string
		end tell
	end tell
end tell


tell application id "com.adobe.photoshop"
	tell settings
		if IDunit is "points" then set ruler units to point units
		if IDunit is "picas" then set ruler units to pica units
		if IDunit is "inches" then set ruler units to inch units
		if IDunit is "inches decimal" then set ruler units to inch units
		if IDunit is "millimeters" then set ruler units to mm units
		if IDunit is "centimeters" then set ruler units to cm units
		if IDunit is "ciceros" then display dialog "ID units don't match PS units"
		if IDunit is "agates" then display dialog "ID units don't match PS units"
		if IDunit is "pixels" then set ruler units to pixel units
	end tell
end tell


I'm currently running OS 12.2.1


Any explanation or fix would be greatly appreciated.

MacBook Pro (2020 and later)

Posted on May 18, 2022 12:27 PM

Reply
Question marked as Top-ranking reply

Posted on May 19, 2022 10:58 AM

Thank you for your response. I've tried setting the IDunit without coercing it, and coercing it, both with no luck. I only need something consistent to identify the unit. It appears that the script editor defines horizontal measurements differently than the script menu. It is classified as a constant, so in the script editor it gets defined as inches (if the unit is found to be inches), but in the script menu, it is defined as zinc (uncoerced), and is «constant****zinc» when coerced. When I change the if statement to if IDunit is "«constant****zinc»"... it never is. That's my first clue that the script menu seems incapable to coerce it into a string (a bug). Instead of trying to figure out the unit, ultimately it was easier to just change the units in both ID and PS (where I was trying to make the two units consistent to do some other task) and then change it back at the end of the script.

Similar questions

2 replies
Question marked as Top-ranking reply

May 19, 2022 10:58 AM in response to Camelot

Thank you for your response. I've tried setting the IDunit without coercing it, and coercing it, both with no luck. I only need something consistent to identify the unit. It appears that the script editor defines horizontal measurements differently than the script menu. It is classified as a constant, so in the script editor it gets defined as inches (if the unit is found to be inches), but in the script menu, it is defined as zinc (uncoerced), and is «constant****zinc» when coerced. When I change the if statement to if IDunit is "«constant****zinc»"... it never is. That's my first clue that the script menu seems incapable to coerce it into a string (a bug). Instead of trying to figure out the unit, ultimately it was easier to just change the units in both ID and PS (where I was trying to make the two units consistent to do some other task) and then change it back at the end of the script.

May 18, 2022 1:42 PM in response to fobioid

I don't use In Design, so hard to be sure, but it sounds like a typical enumeration issue - mostly caused by your (un-needed?) coercion to string.

Any time you take objects out of their native form and degrade to a string, you risk the chance of losing resolution and context.

In this case, horizontal measurement units is much more than a string of "inches", "pica", etc.


So the solution may be to keep it in the native form:


tell application id "com.adobe.indesign"
	tell active document
		tell view preferences
			set IDunit to horizontal measurement units
		end tell
	end tell

	tell settings
		if IDunit is points then set ruler units to point units
		if IDunit is picas then set ruler units to pica units
		if IDunit is inches then set ruler units to inch units
        ...


In this way, IDunit remains as a natural In Design object and there is no ambiguity.


The specifics of this are somewhat dependent on the application dictionary, so you'll need to see what the horizontal measurement unit object looks like.

AppleScript InDesign script doesn't work from script menu

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.