5 Replies Latest reply on Jul 2, 2013 2:40 PM by Muppet Mark

    Scale Photoshop layer using AppleScript

    pathblaster Level 1

      Obviously, this is a Mac PS issue.

       

      I am trying to script scaling a Photoshop layer (a smart object layer) to a specified percentage that I calculate from a layout in InDesign.

      However, I am stumped on the syntax I should use to actually get the layer to resize, or perhaps I don't know how to call out the layer properly.

       

      Here is my code (it is very simple at this point in time:

       

       

      tell application "Adobe InDesign CS6"
                set mySelect to selection
        --error trap to make sure I have graphic content selected
        
                tell active spread of active window
                          set thisBox to item 1 of mySelect
                          set HScale to the absolute horizontal scale of thisBox
        
                end tell
      end tell
      myScaleConversion(HScale)
      set PSScaled to result as real
      
      tell application "Adobe Photoshop CS6"
                set thisLayer to current layer of current document
                set scaleSet to {horizontal scale:PSScaled, vertical scale:PSScaled, anchor:"top left"}
        scale current layer of current document with scaleSet
        
      end tell
      
      
      on myScaleConversion(HScale)
                set ScaleRatio to 2.5 as real
                set PSScale to (ScaleRatio * HScale)
                return PSScale
        
      end myScaleConversion
      
      

       

       

      I would appreciate any help with this. I run this script and no error messages occur, but then again, nothing happens to the Photoshop layer I have targeted.

        • 1. Re: Scale Photoshop layer using AppleScript
          Muppet Mark Level 5

          There are 2 things I see that are not right… top right should a compiled word pair from the apps dictionary… You have it as string…

           

          Now anchor should be anchor position but I can't get this to compile inside your list… hum… if I take it out it works just fine…

           

          tell application "Adobe InDesign CS5"

            activate

                    set mySelect to selection

            --error trap to make sure I have graphic content selected

           

                    tell active spread of active window

                              set thisBox to item 1 of mySelect

                              set HScale to the absolute horizontal scale of thisBox

           

                    end tell

          end tell

           

          myScaleConversion(HScale)

           

          set PSScaled to result as real

           

          tell application "Adobe Photoshop CS5"

            activate

                    set thisLayer to current layer of current document

            --set scaleSet to {horizontal scale:PSScaled, vertical scale:PSScaled, anchor position:top left}

            scale current layer of current document ¬

            horizontal scale PSScaled ¬

            vertical scale PSScaled ¬

            anchor position top left

           

          end tell

           

          on myScaleConversion(HScale)

                    set ScaleRatio to 2.5 as real

                    set PSScale to (ScaleRatio * HScale)

                    return PSScale

           

          end myScaleConversion

          • 2. Re: Scale Photoshop layer using AppleScript
            pathblaster Level 1

            Thanks Mark,

             

            Thanks for your help, Mark. It gets me a lot closer than I was.

             

            I thought that this was what I needed. The syntax is doing something, but the scale command is multiplying the original scale percentage ( the layer is a smart object) by the calculated scale percentage. What I need is to set the layer to the calculated scale percentage.

            • 3. Re: Scale Photoshop layer using AppleScript
              Muppet Mark Level 5

              I could not work out what the point of your sub-routine myScaleConversion was…?

               

              If you want the ID scale % the same value passed to PS then remove the sub call…?

               

              On both sides they are given as percentage value…

              • 4. Re: Scale Photoshop layer using AppleScript
                pathblaster Level 1

                Hi Mark,

                 

                My aim was to accomplish transferring the relative scale of a series of images in an InDesign layout to a master Photoshop layered file. The conversion subroutine was needed to get that relative scale. The issues not seen is that some of these images were transferred into the Photoshop file at large scale percentages (more than 100%).

                Manually I would take the calculated scale percentage and just enter that into the size fields in the Transform options bar. What I hoped would happen, is that this script action would simply enter that calculated percentage into the scale percent. What it did, instead, is multiply the current scale percentage of the layer by the calculated percentage. So if the layer contents were 100%, it worked fine. But if the layer was set to anything over 100%, the results were not what I actually wanted.

                 

                Thanks for the help anyway. There are still severe limitations to what you may accomplish via AppleScript. Are we all going to have to abandon it for JavaScript?

                • 5. Re: Scale Photoshop layer using AppleScript
                  Muppet Mark Level 5

                  Are we all going to have to abandon it for JavaScript? Well I couldn't answer that for you…

                   

                  I changed for the most part about 3 years back… and Im still very much learning it hence ( the muppet )

                   

                  I put it off for a while as forum talk looked like Action Script may replace it… and I might waste my time.

                   

                  In AI & ID you will get access to very much the same thing using AppleScript or ExtendScript… ( scriptUI apart )

                   

                  BR is pretty much ExtendScript only… PS is by far more accessable with action manager syntax ( scriptlistener output )

                   

                  The users here that know PS much better than me will use this over the ExtendScript DOM most of the time…

                   

                  Personally I have found AppleScript has become more problematic over the last few years ( CS versions )… but thats just MO

                   

                  Passing a value app to app as above AppleScript is sooo sooo simple… In ExtendScript bridgetalk is a few hoops more…

                   

                  Pros n cons to each you will have to weigh up what suits your needs best…

                   

                  AppleScript can perform JavaScript in all the above apps if thats an option…?