3 Replies Latest reply on Oct 28, 2014 7:28 AM by rob day

    positioning objects with applescript

    ascotto Level 1

      Hi all, i'm an applescript noob and i began to learn its basics to automate some tricky tasks of my daily work.

      I wrote a very simple code - and it actually works - , but i need to refine it.

      Here it is:

       

      tell application "Adobe InDesign CC 2014"

          tell active document

              tell every master spread

                  tell every page to make rectangle with properties {stroke weight:0, absolute horizontal scale:1, absolute vertical scale:1, fill color:"Paper", transparency settings:{blending settings:{opacity:0.1}}}

              end tell

          end tell

      end tell

       

      This script automatically places my rectangle somewhere on the top left corner - why? - of every page; i tried it on another mac but it doesn't work as well, because the rectangle appears outside the page.

      So, is there a way to tell my rectangle to, for example, snap to the top margin of every page, in the middle? This way there shouldn't be problems anymore...

       

      Hope to find a way, thanks all.

       

      Alessandro

        • 1. Re: positioning objects with applescript
          rob day Adobe Community Professional & MVP

          You position a rectangle via geometric bounds:

           

           

          tell application "Adobe InDesign CS6"   

              tell active document

                  --get the view prefs and set units to inches and the origin to page

                  set viewprefs to properties of view preferences

                  set properties of view preferences to {horizontal measurement units:inches, vertical measurement units:inches, ruler origin:page origin}

                 

                  --the bounds of the rectangle in y1,x1,y2,x2 format

                  --y1 and x1 are the x,y coordinates of the upper left corner relative to the ruler settings

                  --y2 and x2 are the bottom right corner

                  --so this makes a 3" square

                  set mybounds to {1.0, 2.0, 4.0, 5.0}

                  tell every master spread

                      tell every page to make rectangle with properties {geometric bounds:mybounds, stroke weight:0, fill color:"Black"}

                  end tell

                 

                    --reset rulers

                  set properties of view preferences to viewprefs

              end tell

          end tell

          • 2. Re: positioning objects with applescript
            ascotto Level 1

            Thanks a lot, I'll try it asap, it seems it could work

             

            Since you're the only one who answered, is there a way to run the script as a "single" action? I mean, with a click I can run several automatic actions, but when I cmd+z it undoes actions one by one: it would be great if I could undo the entire script with a single cmd+z...

             

            Thanks again, bye!

            • 3. Re: positioning objects with applescript
              rob day Adobe Community Professional & MVP

              I don't think so. You could run a save at the beginning of a script and then there would be the option to revert.