3 Replies Latest reply on Jul 1, 2013 6:44 AM by John Hawkinson

    Simple Square Up script for Windows

    E Diane King Level 2

      I've been using a simple Applescript on my Mac installation of Indesign for years called Square Up CS. It's a very handy little script that defaults a selected object back to a simple retangle. I find it extraordinarily useful when I've bungled up a text box's properties by accidentally moving a corner or needing it to go back to a normal text box after editing its shape for some reason. I am switching over to a Windows computer full time and would dearly love to port this script over to my new computer, but I'm not a scripting guru and have no idea how to write this in Javascript. Anyone able to help?

       

      tell application "Adobe InDesign CS6"

          set {a, b, c, d} to «class gbnd» of selection

          set «class plst» of «class ppth» 1 of selection to {{b, a}, {d, a}, {d, c}, {b, c}}

      end tell

        • 1. Re: Simple Square Up script for Windows
          John Hawkinson Level 5

          Hi, Diane.

           

          Step one is to translate the Applescript coding back into human-readable Applescript, which you do by pasting into the Applescript Editor and hitting Compile. You get this:

           

           

          tell application "Adobe InDesign CS6"
              set {a, b, c, d} to geometric bounds of selection
              set entire path of path 1 of selection to {{b, a}, {d, a}, {d, c}, {b, c}}
          end tell
          

           

          Step two:

          Here is the translation into Javascript. Note that in JavaScript, arrays (geometric bounds and paths) start counting at zero, rather than one, so "path 1" becomes "paths[0]", etc.; also, we refer to "app.selection[0]" rather than "selection", because there can be multiple selections, and AppleScript lets you say "selection" to mean the first one, but JavaScript requires you to be explicit:

           

           

          var abcd, a, b, c, d;
          abcd = app.selection[0].geometricBounds;
          a=abcd[0]; b=abcd[1]; c=abcd[2]; d=abcd[3];
          
          app.selection[0].paths[0].entirePath = [ [b,a], [d,a], [d,c], [b,c] ];
          

           

          I'm not 100% sure what your test case is, so if it turns out the order of numbers in the entirePath array is different between Javascript and AppleScript, then something might go wrong. I don't think so, but please od test it.

          • 2. Re: Simple Square Up script for Windows
            E Diane King Level 2

            Thanks, John!  That worked. I appreciate your expertise and willingness to help and even instruct. Still not sure I could write a Javascript, but I at least understand better the syntax from your explanation.

            • 3. Re: Simple Square Up script for Windows
              John Hawkinson Level 5

              You're welcome. It wasn't intended as a full-out tutorial, but I did want to explain the obvious changes that might seem odd if you didn't know why they were the case...