Re: INDESIGN: Coercing a String to a Constant
Re: INDESIGN: Coercing a String to a Constant
- Subject: Re: INDESIGN: Coercing a String to a Constant
- From: Rick Gordon <email@hidden>
- Date: Wed, 12 Oct 2011 12:09:37 -0700
Title: Re: INDESIGN: Coercing a String to a
Constant
Thanks, that's very helpful. As an aside, the script was for
personal use, so I had just include the units that I had a possible
conversion need for, ciceros and agates not being among them.
In the general sense, how can I easily access the raw codes for
application constants. I don't own Script Debugger, which I think will
show raw codes. (Sometimes I get them from having generated errors,
usually just in the course of doing business.)
Rick Gordon
------------------
On 10/12/11 at 10:42 PM +1100, Shane Stanley wrote in a message
entitled
"Re: INDESIGN: Coercing a String to a Constant":
On 12/10/2011, at 7:58 PM, Rick Gordon
wrote:
"measurement units for "
& aTargetText & " to:" default items {aTarget as
text}
And that's going to behave differently
depending on whether it's run from a script editor or not, because
when you coerce an enumeration to text, what you get depends on
whether the app's dictionary is available to translate it into
"proper" terminology, or whether you get back the
four-letter code.
In the scheme of things, the odd
"run script" hack is neither here nor there. But why keep
fighting enumerations? They're not that hard to use. (Having said
that, there's a potential wrinkle in InDesign because of terminology
conflicts with AS's built-in units.)
Anyway, here's a rework of your script
(which has another potential problem: you don't offer all the units
available):
set vChanged to false
-- do enum list outside InDesign's
scope to avoid compiling as AS units
set vUnitsEnumList to {«constant
****zpoi», «constant ****zpic», «constant
****zinc», «constant ****zind», «constant
****zmms», «constant ****zcms», «constant
****zpix»}
tell application "Adobe
InDesign CS5"
set
vApp to it
set
vAppName to name
set
vUnitsTextList to {"points", "picas",
"inches", "inches decimal",
"millimeters", "centimeters",
"pixels"}
if
exists document 1 then
--TARGET FRONT DOCUMENT PREFS
set
vTarget to document 1
set
vTargetText to return & "document " & name of
document 1
else
--TARGET APP PREFS
set
vTarget to vApp
set
vTargetText to return & vAppName
end
if
tell
view preferences of vTarget
set
vViewPrefs to it
if
horizontal measurement units is equal to vertical measurement units
then
--ASSUMES WE WANT TO CONTINUE WITH SYCHRONIZED H & V
VALUES
set
vMeasurementPropertyText to ""
try
set
horizontal measurement units to my
fSetMeasurement(vMeasurementPropertyText, vTargetText, vUnitsTextList,
vAppName, horizontal measurement units of vViewPrefs,
vUnitsEnumList)
set
vChanged to true
set
vertical measurement units to horizontal measurement
units
set
vChanged to true
end
try
else
--H & V VALUES ARE ALREADY DIFFERENT SO WE'LL GO WITH
THAT.
set
vMeasurementPropertyText to "horizontal "
try
set
horizontal measurement units to my
fSetMeasurement(vMeasurementPropertyText, vTargetText, vUnitsTextList,
vAppName, horizontal measurement units of vViewPrefs,
vUnitsEnumList)
set
vChanged to true
end
try
set
vMeasurementPropertyText to "vertical "
try
set
vertical measurement units to my
fSetMeasurement(vMeasurementPropertyText, vTargetText, vUnitsTextList,
vAppName, vertical measurement units of vViewPrefs,
vUnitsEnumList)
set
vChanged to true
end
try
end
if
return {horizontal measurement units, vertical measurement
units, vChanged}
end
tell
end tell
on
fSetMeasurement(aMeasurementPropertyText, aTargetText, aUnitsTextList,
aAppName, aTarget, vUnitsEnumList)
repeat
with i from 1 to count of vUnitsEnumList
set
oneUnit to item i of vUnitsEnumList
if
aTarget = oneUnit then
set
defaultitems to {item i of aUnitsTextList}
exit
repeat
end
if
end
repeat
set
vResult to (choose from list aUnitsTextList ¬
with
prompt "Set " & aMeasurementPropertyText &
¬
"measurement units for " & aTargetText & "
to:" default items defaultitems ¬
without multiple selections allowed and empty selection
allowed)
if
vResult is false then
-- whatever
else
set
choiceText to item 1 of vResult
repeat with i from 1 to count of
aUnitsTextList
set
oneUnit to item i of aUnitsTextList
if
then
return item i of vUnitsEnumList
end
if
end
repeat
end
if
end fSetMeasurement
--
Shane Stanley <email@hidden>
'AppleScriptObjC Explored' <www.macosxautomation.com/applescript/apps/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list
(email@hidden)
Help/Unsubscribe/Update your Subscription:
>gordon.com
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
--
___________________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________________
WWW: http://www.shelterpub.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden