5 Replies Latest reply on May 15, 2012 9:13 AM by Muppet Mark

    Cannot open a file by Applescript

    Alan Shutko Level 1

      With Photoshop CS6, I am getting an error trying to open a file. This breaks a few of my scripts which continue to work with CS5.

       

      This code, copied almost exactly from the CS6 Applescript Reference, returns

       

      error "Adobe Photoshop CS6 got an error: File some object wasn’t found." number -43

       

      Passing myFilePath to Finder works perfectly fine to open the alias.

       

      tell application "Adobe Photoshop CS6"

                set myFilePath to alias "Macintosh HD:Users:ats:Downloads:Photoshop-CS6-AppleScript-Ref.pdf"

                tell application "Finder"

        open myFilePath

                end tell

        open myFilePath as PDF with options {class:PDF open options, height:pixels 100, width:pixels 200, mode:RGB, resolution:72, use antialias:true, page:1, constrain proportions:false}

      end tell

        • 1. Re: Cannot open a file by Applescript
          Muppet Mark Level 5

          That's from the guide? Hum looks back to front to me… You want Finder or system events to get the file path and Photoshop to open it…

          • 2. Re: Cannot open a file by Applescript
            Alan Shutko Level 1

            Technically, the guide was:

             

            tell application "Adobe Photoshop CS6"
            set myFilePath to alias "Data:docsamples:testfiles:PdfTest.pdf" open myFilePath as PDF with options ¬

            {class:PDF open options, height:pixels 100, width:pixels 200, ¬

            mode:RGB, resolution:72, use antialias:true, page:1, ¬

            constrain proportions:false}

            end tell

             

            I modified it to fit my pathname, and added the tell block for Finder to test whether the file alias was openable.

            • 3. Re: Cannot open a file by Applescript
              Muppet Mark Level 5

              Photoshop messed up quite a lot of peoples AppleScripts with CS5 it didn't like Finder alias specifiers it preferred strings… Setting a file as alias should confrim the path existence…

              1 person found this helpful
              • 4. Re: Cannot open a file by Applescript
                Alan Shutko Level 1

                Thanks. That hint got me going.  I ended up moving the alias down a line from setting myFilePath to the open command. This works.

                 

                tell application "Adobe Photoshop CS6"

                          set myFilePath to "Macintosh HD:Users:ats:Downloads:Photoshop-CS6-AppleScript-Ref.pdf"

                  open alias myFilePath as PDF with options {class:PDF open options, height:pixels 100, width:pixels 200, mode:RGB, resolution:72, use antialias:true, page:1, constrain proportions:false}

                end tell


                • 5. Re: Cannot open a file by Applescript
                  Muppet Mark Level 5

                  Yeah that looks better… I don't have CS6 so I wasn't able to check… With CS5 things changed with using File & Alias I wasn't too sure if it had been swapped back… Untested…

                   

                  set myFilePath to "Macintosh HD:Users:ats:Downloads:Photoshop-CS6-AppleScript-Ref.pdf" -- a string

                  -- then coerce inside tell app block

                  tell application "Adobe Photoshop CS5"

                    open alias myFilePath as PDF with options ¬

                                      {class:PDF open options, height:pixels 100, width:pixels 200, mode:RGB, resolution:72, use antialias:true, page:1, constrain proportions:false}

                  end tell

                  -- ditto here

                  tell application "Adobe Photoshop CS5"

                    open file myFilePath as PDF with options ¬

                                      {class:PDF open options, height:pixels 100, width:pixels 200, mode:RGB, resolution:72, use antialias:true, page:1, constrain proportions:false}

                  end tell