1 2 Previous Next 79 Replies Latest reply: Nov 13, 2014 1:04 PM by GuyJr RSS

    Changes to Photoshop CS5 and Applescript

    Peter Payne Community Member

      Looks like there are some major Applescript changes to CS5, which is unwelcome for anyone with existing scripts. From what I can see, the difference (that affect me anyway) are

       

      a) PSCS5 seems to dislike referring to files with "as alias" and removing this from my scripts helps them to work, whereas other apps need it, as did previous

      b) apparently script support for referring to the currently document has changed. "if visible layer of current document is true then..." no longer works, nor do document 0, document 1, etc. Anyone know how to refer to the current document?

      c) support for history doesn't seem to be there anymore. I cannot seem to use AS commands like, "set myState to history states as list" or "set current history state to history state newState" were awesome for my workflow, but are they impossible to achieve now?

      d) One more. The important "set docref to make new document with properties {height: 150, width: 150}" is also broken. How would one make a new document in Applescript?

        • 1. Re: Changes to Photoshop CS5 and Applescript
          robotspacer

          They seem to have removed a huge number of AppleScript features, and the dictionary is basically empty. The developer center doesn't have any info on CS5 either: http://www.adobe.com/devnet/photoshop/scripting/ So apparently they expect us to just guess at what works.

           

          Presumably they want us to start using JavaScript instead of AppleScript. But the worst part is that the "do javascript" command is apparently gone as well, which would have at least given us an easy way to transition existing scripts.

           

          What a disaster.

          • 2. Re: Changes to Photoshop CS5 and Applescript
            robotspacer Community Member

            I just found the AppleScript documentation in /Applications/Adobe Photoshop CS5/Scripting/Documents/. But I don't think it's even accurate. Here's a very simple sample they give:

             

            tell application "Adobe Photoshop CS5"
                 filter current layer of the current document using lens blur with options {class:lens blur, radius:13}
            end tell
            

             

            If I enter this in AppleScript Editor and try to compile it, it selects the word "current" and tells me "Expected end of line but found identifier." It doesn't even recognize "filter" as a command. If I just change that 5 to a 4, it works fine in CS4.

             

            Here's one way to run a JavaScript file from AppleScript:

             

            tell application "Adobe Photoshop CS5" to open file "Path:to:file.jsx"
            

             

            Of course there's no way to pass any arguments this way, so that greatly limits its usefulness. But perhaps this will be helpful to some people. I'm assuming the JavaScript stuff all works fine, as that seems to be their focus these days.

             

            The really strange thing is that certain things seem to work fine in AppleScripts that are already compiled (using CS4). But if I try to re-save those scripts with CS5 installed, I get errors.

            • 3. Re: Changes to Photoshop CS5 and Applescript
              Michael L Hale Community Member
              I'm assuming the JavaScript stuff all works fine, as that seems to be their focus these days.

               

              It doesn't surprise me that there are errors in Applescript and/or it's documentation. There are errors in both javascript and it's guides.

               

              I would surprise me if those errors are intentional to force anyone to switch to javascript.

               

              My guess would be that any new Applescript errors are a result of either the Apple forced API change or the change to 64 bit. That combined with the fact that there are fewer Applescript developers for Photoshop to report any errors when the product was in prerelease.

               

              I reported several javascript errors during the prerelease. Most where not fixed. I didn't assume that was because Adobe didn't want javascript developers. I assumed that they did not have time or resources to deal with those because of the other work needed for this cycle.

              • 4. Re: Changes to Photoshop CS5 and Applescript
                robotspacer Community Member

                Yeah, after investigating it further I think it's just buggy, as opposed to having features intentionally removed. I was finally able to get a complex script working again with minimal changes by doing this:

                 

                • Installed Photoshop CS4 again.
                • Had my scripts call "Adobe Photoshop CS4" or just "Adobe Photoshop CS" rather than CS5.
                • If I was ever asked to locate Photoshop while compiling, I selected CS4, not CS5. Selecting CS5 here, or calling "Adobe Photoshop CS5" in the script will result in major errors.
                • Once the script was compiled (saved), I moved my Photoshop CS4 folder to the trash (without emptying it). This made sure the script ran in CS5. Then if I needed to make further changes, I could just drag CS4 out of the trash and back into place.
                • It was also a big help to add [b]try… on error… end try[/b] blocks around things that seemed to be causing problems in CS5.

                 

                Peter, hopefully this will help you too. By doing the above I've found that "current document", "as alias", and other things work as expected in CS5, even though they were previously giving me errors.

                 

                Can anyone tell us the best place to report these bugs? I'd love to do what I can to help them get fixed.

                • 5. Re: Changes to Photoshop CS5 and Applescript
                  Michael L Hale Community Member

                  You should be able to report bugs here https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

                   

                  You will need an Adobe ID, which you should already have.

                  • 6. Re: Changes to Photoshop CS5 and Applescript
                    Sideways Design Community Member

                    Has anyone else noticed that all but the standard command suites are missing? Drag-drop CS5 onto the AppleScript Editor icon and see if there's more than "Standard Suite", "Text Suite" and "Type Definitions".

                     

                    My scripts in CS5 generally run with some modification, but the commands not in these dictionaries are called by event code, not standard AppleScript.

                     

                    Also, I've noticed that they've changed the way they refer to the active document, but without the proper dictionaries, I can't develop a workaround.

                     

                    I really hope Adobe doesn't sit on this until CS6 -- it's quite a dealbreaker.

                    • 7. Re: Changes to Photoshop CS5 and Applescript
                      robotspacer Community Member

                      Thanks Michael, I just filed a bug report:

                       

                      ******BUG******

                      Concise problem statement:

                      Photoshop CS5 for Mac has some major issues with AppleScript. Most (but not all) scripts seem to run okay, but all of the custom commands are missing from the dictionary, and almost nothing will compile. The only workaround I've found is to install CS4, compile against that, then run the script with CS5.

                       

                      Steps to reproduce bug:

                       

                      1. Open AppleScript Editor

                      2. Enter a simple script from the AppleScript guide, like:

                      tell application "Adobe Photoshop CS5"

                           filter current layer of the current document using lens blur with options {class:lens blur, radius:13}

                      end tell

                      3. Click Compile or Run.

                       

                      Results:

                      An error occurs: "Expected end of line but found identifier."

                       

                      Expected results:

                      The script should compile with no errors, or run--applying a lens blur to the front-most document in Photoshop CS5.

                       

                      If CS5 is changed to CS4, the script works perfectly. (If it the script is saved as an application and CS4 is deleted, it will probably even work in CS5. Compiling is the main issue.)

                       

                      For anyone else having problems I'd encourage you to do the same.

                      • 8. Re: Changes to Photoshop CS5 and Applescript
                        JonLo Adobe Employee

                        In some situations Applescript Editor does run into communication problem with Photoshop. The safest way to make sure you will see all the terminologies in the library is to follow the steps below:

                        1. Save your script

                        2. Quit Applescript Editor

                        3. Quit Photoshop

                        4. Relaunch Photoshop

                        5. Open your saved script and recompile.

                         

                        To make sure your script will run every time, you could save your compiled script as an Applescript app, then there is much less chance of getting into "Compiling errors."

                         

                        For "as alias" problem, it had been identified the Standard library and Photoshop have different interpretation of the alias. To work around the problem, you could first cast the alias as "string", then in Photoshop cast it back "as alias." This should work around the current problem. For example:

                         

                        set theImage to (choose file with prompt "Please select an image file:") as string  --This is from StandardAdditions of AppleScript Dictionary
                        tell application "Adobe Photoshop CS5"
                           open alias theImage --"open file theImage" should work (w/o quote), too.
                        end tell

                        • 9. Re: Changes to Photoshop CS5 and Applescript
                          Sideways Design Community Member

                          Thank you for this reply; I'll be sure to try the steps do see if I can reestablish a connection to Photoshop if it goes wonky after a lot of scripting.

                           

                          I should have been more specific regarding document handling.

                           

                          With CS4 I had no problem in setting a variable as a reference to the "front document", which I would then use via a tell statement; this would ensure that scripted actions were directed at a particular document, in case I inadvertently switched windows, or if the script action requires that the intended document actually is the front document.

                           

                          It worked flawlessly in CS4; I cannot figure out how to do this in CS5.

                          • 10. Re: Changes to Photoshop CS5 and Applescript
                            JonLo Adobe Employee

                            Could you give me an example of what kind of problem you encountered?

                            • 11. Re: Changes to Photoshop CS5 and Applescript
                              Sideways Design Community Member

                              Try this:

                               

                              tell application "Adobe Photoshop CS4"

                              set psDocRef to front document

                              end tell

                               

                              and then try this:

                               

                              tell application "Adobe Photoshop CS5"

                              set psDocRef to front document

                              end tell

                              • 12. Re: Changes to Photoshop CS5 and Applescript
                                JonLo Adobe Employee

                                For AppleScript, you could use "current" to set focus to the frontmost object. So, you could change the focus by using "current" as follows:

                                 

                                tell application "Adobe Photoshop CS5"

                                    activate

                                    set psDocRef to make new document -- first document has the focus

                                    make new document -- now, second document has the focus

                                    set current document to psDocRef -- the first document get the focus again.

                                end tell

                                • 13. Re: Changes to Photoshop CS5 and Applescript
                                  tomdev

                                  AppleScript support is effectively broken.

                                  We have compiled scripts which fail to execute properly. Once this happens, every AppleScript command then fails including trying to compile new commands using the script editor (the 'current document' error mentioned above).

                                  This breaks our application which was working great for years on CS3 and CS4.

                                   

                                  Can we expect Adobe to fix this in a minor update of PS CS5?

                                  • 14. Re: Changes to Photoshop CS5 and Applescript
                                    robotspacer Community Member

                                    Ah—making sure to launch Photoshop CS5 before AppleScript Editor (or Xcode) does seem to fix the problems for me. The dictionary shows up correctly, and the compiling errors are gone. Thank you!

                                    • 15. Re: Changes to Photoshop CS5 and Applescript
                                      Jesper Storm Bache Adobe Employee

                                      This sounds like an issue where the Photoshop terminology gets dropped on the floor because Cocoa installs its own terminology handler on top of Photoshop's handler.

                                      If I follow the steps described in this thread, then I do not see the problem on my machine.

                                      My test case is:

                                      - Launch the AppleScript Editor

                                      - Enter:

                                       

                                      tell application "Adobe Photoshop CS5"

                                      make new document

                                      filter current layer of the current document using lens blur with options {class:lens blur, radius:13}

                                      end tell

                                      - Click compile (or hit enter)

                                      Photoshop launches and the script compiles correctly

                                       

                                       

                                      There could be some OS version sensitivity here. I am currently testing on 10.6.3.

                                      Could you let me know which version of OSX that you are using?

                                      • 16. Re: Changes to Photoshop CS5 and Applescript
                                        Jesper Storm Bache Adobe Employee

                                        Besides information about the OS version could you also let me know:

                                        - whether or not your are running in 32 bit mode

                                        - which 3rd party plug-ins (if any) you are using

                                        - which scripting additions that you are using

                                        Thanks,

                                        Jesper

                                        • 17. Re: Changes to Photoshop CS5 and Applescript
                                          SMP_Vince

                                          - Mac OS X 10.6.3 french, CS5 french

                                          - 64 bits mode

                                          - no third parties plug-ins

                                           

                                          OSAXEN : Adobe Unit Types.osax (from cs5 installation), Satimage.osax,XMLLib.osax (both are from sati image), SIMBL.osax,SmartScroll.osax,XMLLib.osax,TextExpander Addition.osax

                                          • 18. Re: Changes to Photoshop CS5 and Applescript
                                            tomdev Community Member

                                            - Mac OS X 10.6.3, CS5 French

                                            - 64-bit (iMac Core 2 Duo)

                                            - No third-party plugin

                                            - No scripting addition

                                            • 19. Re: Changes to Photoshop CS5 and Applescript
                                              Jesper Storm Bache Adobe Employee

                                              D'accord.

                                              Besides using a French version of Photoshop you should have the same version as I do. Could I ask you to post specific steps on how to repro from system restart to failure?

                                              You'll see me test case earlier in this thread & that case does not fail on my system.

                                              Thank you,

                                              Jesper

                                              • 20. Re: Changes to Photoshop CS5 and Applescript
                                                tomdev Community Member

                                                Test case:

                                                 

                                                1. Place an "image.tif" on your desktop

                                                2. Open another image in Photoshop

                                                3. Run the following script

                                                 

                                                 

                                                tell application "Adobe Photoshop CS5"

                                                activate

                                                set masterDocument to current document

                                                open file ((path to home folder as string) & "Desktop:image.tif")

                                                height of masterDocument

                                                end tell

                                                 

                                                • 21. Re: Changes to Photoshop CS5 and Applescript
                                                  SMP_Vince Community Member

                                                  Just did Error

                                                   

                                                   

                                                   

                                                  error "Erreur dans Adobe Photoshop CS5 : Il est impossible d’obtenir current document." number -1728 from current document

                                                  • 22. Re: Changes to Photoshop CS5 and Applescript
                                                    Jesper Storm Bache Adobe Employee

                                                    Thanks for the repro steps.

                                                    It appears that the "open" command affects the terminology.

                                                    In the following script the first "height of current document" works, while the second fails:

                                                     

                                                    tell application "Adobe Photoshop CS5"

                                                    activate

                                                    height of current document

                                                    open file ((path to home folder as string) & "Desktop:image.tif")

                                                    height of current document

                                                    end tell

                                                    When we are in the failure mode everything fails so it does appear that Cocoa in some way is overriding our event handlers.
                                                    Again thanks for reporting this issue and providing a test case.

                                                    • 23. Re: Changes to Photoshop CS5 and Applescript
                                                      tomdev Community Member

                                                      I'm glad to see you're getting what is going wrong.

                                                      If I can be of any help, please tell me! I'd love to see this fixed.

                                                       

                                                      Thanks!

                                                      • 24. Re: Changes to Photoshop CS5 and Applescript
                                                        Jesper Storm Bache Adobe Employee

                                                        Based on the test case from this thread, we have been able to make some changes that solves the problems that we are seeing.

                                                        If you post your email I'd be happe to email you a pre-release version of the changes so you can verify whether or not it solves the problems that you are seeing on your system (the size is between 3 and 4 MB).

                                                        If you do post your email address make sure to scramble it slightly to minimize the risk of getting spam from web-crawlers.

                                                        For example: "tom" at "company dot fr"

                                                        Again, Thanks for your help.

                                                        • 25. Re: Changes to Photoshop CS5 and Applescript
                                                          tomdev Community Member

                                                          Excellent, that was quick.

                                                          I'd be happy to test and report back to you.

                                                          I just sent you a private message with my e-mail address, is that ok?

                                                          • 26. Re: Changes to Photoshop CS5 and Applescript
                                                            SMP_Vince Community Member

                                                            Please send it at "vincentdigitallife"  gmail  dot com

                                                            • 27. Re: Changes to Photoshop CS5 and Applescript
                                                              Sideways Design Community Member

                                                              I'd be happy to kick it around, too.

                                                               

                                                              richard (at) sidewaysdesign (dot) com

                                                              • 28. Re: Changes to Photoshop CS5 and Applescript
                                                                robotspacer Community Member

                                                                For what it's worth I am no longer able to reproduce the problems I was having. It was happening very consistently until I reinstalled Photoshop CS4. Now, even after uninstalling CS4 again, I can't recreate the problem.

                                                                • 29. Re: Changes to Photoshop CS5 and Applescript
                                                                  SMP_Vince Community Member

                                                                  New plugin works great for me, thanks a lot !

                                                                  • 30. Re: Changes to Photoshop CS5 and Applescript
                                                                    null_node

                                                                    hoping to try this patch as well. this bug has put a halt on my workflow

                                                                     

                                                                    trapdoormg at gmail.com

                                                                    • 31. Re: Changes to Photoshop CS5 and Applescript
                                                                      null_node Community Member

                                                                      thank you for the incredibly fast response jesper. the plugin solved my problems!!

                                                                      • 32. Re: Changes to Photoshop CS5 and Applescript
                                                                        Jesper Storm Bache Adobe Employee

                                                                        You are welcome.

                                                                        Thank you for letting us know that this change fixes the problem that you are encountering.

                                                                        Jesper

                                                                        • 33. Re: Changes to Photoshop CS5 and Applescript
                                                                          tomdev Community Member

                                                                          When can we expect this patch to be pushed to every CS5 user out there?

                                                                          • 34. Re: Changes to Photoshop CS5 and Applescript
                                                                            surreysud Community Member

                                                                            I just installed PS CS5 and am unable to use my old applescript app for the reasons given above. I stupidly scrapped the former Photoshop (CS2) and am unable to reinstall it so I am really stuck. I tried editing the AS code and I could run it in XCode in debug mode but the syntax colour wouldn't show. The text remained black for new typing. Very strange. Other AS apps not involving CS5 still worked as expected.

                                                                             

                                                                            Upon an error state I found that the Photoshop app had lost its Dictionary. (Applescript Editor came up blank.) Restarting Photoshop fixed this.

                                                                             

                                                                            After much frustration I found this thread. Thanks. Please email the CS5 fix to mikey666*****at*****shaw*****dot*****ca.

                                                                            • 35. Re: Changes to Photoshop CS5 and Applescript
                                                                              surreysud Community Member

                                                                              Thanks for the prompt reply.

                                                                              • 36. Re: Changes to Photoshop CS5 and Applescript
                                                                                Cut Copy Design

                                                                                Hi Jesper,

                                                                                 

                                                                                I ran across this discussion searching for a fix to my applescripting errors with Photoshop CS5. I was wondering if I could get that beta fix as well. You can email it to me at chrisbernal.design [at] gmail.com

                                                                                 

                                                                                Thanks in advance.

                                                                                • 37. Re: Changes to Photoshop CS5 and Applescript
                                                                                  Cut Copy Design Community Member

                                                                                  Hey Jesper,

                                                                                   

                                                                                  Thanks for the fast response. Just wanted to let you know that the updated plugin fixed all of my errors.

                                                                                   

                                                                                  Thanks again.

                                                                                  • 38. Re: Changes to Photoshop CS5 and Applescript
                                                                                    Jesper Storm Bache Adobe Employee

                                                                                    Excellent & thanks for letting me know.

                                                                                    Jesper

                                                                                    • 39. Re: Changes to Photoshop CS5 and Applescript
                                                                                      SuperMacGuy Community Member

                                                                                      Please also send me the patch plug in.

                                                                                       

                                                                                      chris.paveglio *at*  clippermagazine  *dot* com

                                                                                      1 2 Previous Next