• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: INDESIGN: Coercing a String to a Constant
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: INDESIGN: Coercing a String to a Constant


  • Subject: Re: INDESIGN: Coercing a String to a Constant
  • From: Shane Stanley <email@hidden>
  • Date: Wed, 12 Oct 2011 22:42:56 +1100

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 oneUnit = choiceText 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:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: INDESIGN: Coercing a String to a Constant
      • From: Rick Gordon <email@hidden>
References: 
 >INDESIGN: Coercing a String to a Constant (From: Rick Gordon <email@hidden>)
 >Re: INDESIGN: Coercing a String to a Constant (From: Shane Stanley <email@hidden>)
 >Re: INDESIGN: Coercing a String to a Constant (From: Rick Gordon <email@hidden>)
 >Re: INDESIGN: Coercing a String to a Constant (From: Rick Gordon <email@hidden>)

  • Prev by Date: Re: Filter a text string
  • Next by Date: Re: Safari Status Bar
  • Previous by thread: Re: INDESIGN: Coercing a String to a Constant
  • Next by thread: Re: INDESIGN: Coercing a String to a Constant
  • Index(es):
    • Date
    • Thread