3 Replies Latest reply on Jun 18, 2014 2:28 PM by CulinaryGeek

    Variables not returning correct value if script is run in InDesign

    CulinaryGeek Level 1

      Ok, here is a snippet of my script.

       

      tell application "Adobe InDesign CC"

        set aspActiveDocument to active document

        tell view preferences of aspActiveDocument

        --get horizontal measurement units

        set aspOrigHorizonalMeasurementUnits to horizontal measurement units

        set aspOrigVerticalMeasurementUnits to vertical measurement units

        set aspTryThis to horizontal measurement units as string

        --set horizontal measurement units

        set horizontal measurement units to millimeters

        set vertical measurement units to millimeters

        end tell

       

        set aspDocHeight to item 3 of bounds of page 1 of aspActiveDocument

        set aspDocHeight to aspDocHeight as string

        set aspDocWidth to item 4 of bounds of page 1 of aspActiveDocument

        set aspDocWidth to aspDocWidth as string

       

        set aspSizeInfo to (aspDocWidth & " x " & aspDocHeight & " " & aspTryThis) as string

        display dialog aspSizeInfo

      end tell


      If I run it from AppleScript Editor I get: 215.9 x 279.4 millimeters

       

      If I save it as an Application I get: 215.9 x 279.4 <<constant ****zmms>>

       

      If I run the script from the scripts panel in InDesign I get: 215.9 x 279.4 <<constant ****zmms>>

       

      Anyone have any idea why or how to fix this issue?



        • 1. Re: Variables not returning correct value if script is run in InDesign
          Mary Posner Level 3

          I got the same results when I tested your script in CS5.5; it was okay when run via Script Debugger, but returned the raw code when saved as an app. I found the below in another discussion about coercing constants, and it seemed to work for me in CS5.5. Try adding this at the top of your script:

           

          run script "tell application \"Adobe InDesign CC\"" & return & "end tell"


           

          From what I understand, this may result in a bit of a performance hit as it's forcing the InDesign dictionary to load every time it's run, but it ran pretty quickly for me and did produce the correct dialog.

          • 2. Re: Variables not returning correct value if script is run in InDesign
            zeRafio

            HI CulinaryGeek,

             

            There is a problem with your code.

            You're asking for measurement units before setting them.

             

            If Indesign returns a constant expressed in <<chevrons>>, it's a bug.

             

            But your script could be simplified:

             

            tell application "Adobe InDesign CC"

              set aspActiveDocument to active document

              tell view preferences of aspActiveDocument

              --get horizontal measurement units

              set aspOrigHorizonalMeasurementUnits to horizontal measurement units

              set aspOrigVerticalMeasurementUnits to vertical measurement units

             

              --set horizontal measurement units

              set horizontal measurement units to millimeters

              set vertical measurement units to millimeters

              end tell

             

              set aspDocHeight to item 3 of bounds of page 1 of aspActiveDocument

              set aspDocWidth to item 4 of bounds of page 1 of aspActiveDocument

             

              set aspSizeInfo to (""& aspDocWidth & " x " & aspDocHeight & " millimeters") as string

              display dialog aspSizeInfo

            end tell