29 Replies Latest reply on Jul 23, 2013 5:20 PM by Zetta

    Is it worth it for me to learn scripting in PS?

    spdorsey6969 Level 1

      I have absolutely NO experience with javascript, and I have failed miserably every time I have attempted to learn. Should I leave Photoshop scripting to the pros?

       

      I work in an environment where we are using PS to create super-high-end imagery seen the world over. We are doing things here that make Adobe's engineers' heads explode. We are automating a lot of our process, and actions have gotten us only so far. Scripting is the next logical step, but I'm not sure if it's within my abilities.

        • 1. Re: Is it worth it for me to learn scripting in PS?
          Michael L Hale Level 5

          I think only you can determine if it's worth your time to learn to script Photoshop. It may take some time and effort but I don't think it's beyond most peoples abilities.

           

          I think when talking about scripting with javascript you need to separate the core language from whatever Object Model is being used. I think javascript itself is not that hard to learn. It's not that complex a language. I think it's working with an object model that causes the most trouble. The Photoshop Object Model is much different than the Browser DOM used in scripting web pages.

           

          It helps if you already have a good knowledge of Photoshop. With that knowledge learning the Photoshop Object Model is much easier. You would already know about Documents, layers, channels, etc. And you would know what Photoshop can do with those classes, have an idea of what properties and methods they might have.

           

          When I started scripting Photoshop I found learning the Photoshop Object Model much easier than the browser DOM.

          • 2. Re: Is it worth it for me to learn scripting in PS?
            spdorsey6969 Level 1

            Thanks for the reply.

             

              I know PS VERY well, so that is encouraging. Do you know of any resources for getting started for a true beginner like me?

             

              I'd suppose that learning the basics of JS would come first.

             

            Thanks,

             

            ------S

            • 3. Re: Is it worth it for me to learn scripting in PS?
              Michael L Hale Level 5

              I would recommend a course at lynda.com http://www.lynda.com/JavaScript-tutorials/Foundations-of-Programming-Fundamentals/83603-2. html

               

              It covers basic scripting/programming and uses javascript as the example language. It focus mainly on the core javascript features and doesn't spend much time on the Browser DOM( which wouldn't be helpful for Photoshop scripting ).

               

              I don't think there are really any good books or videos on scripting Photoshop. I think the ones that exists are either old or not too helpful.

               

              You may already have the Photoshop JavaScript Reference on your computer. It was installed by default until the last version or so. If you are using a new version you can download the reference from Adobe.

               

              I would suggest that you start with a task you want to automate that can't be done with an action. That way you learn only what you need to know, when you need to know it and have something useful when you are done. In other words don't try to learn how to script everything at once. Just learn how to script small parts at a time and build up your scripting skills that way. Your first useful script may be simple but you can feel good about having written it.

               

              When you get stuck( and we all do at some point ) post a question here if you can't find it already answered. And don't feel bad about asking 'noobie' questions. We all were new to scripting at one time or another and you should see some of my questions when I started.

              • 4. Re: Is it worth it for me to learn scripting in PS?
                JJMack Most Valuable Participant

                Like Actions can not record all steps you can do you can do in Photoshop.  Adobe Photoshop DOM does not have methods to use all of Photoshop features.

                 

                Adobe provides a plug-in names the scriptlistner.  This plugin is sort of like the Actions Palette recorder without controls.  It records everything you do in Photoshop that is record-able in actions into two log file.  One Javascript code the other visual basic code  which is like Actions steps. Step step step. The code in these steps is code to that uses the Action Manager to perform the steps,  The code is not very readable. 

                 

                When you see code in a Photoshop that not all the readable it most likely.  Scriptlistener code for the action manager.  Often the code has been modified by the script author. Where they replace some hard coded values recorded into steps used to set parameters passes to the action manager with variables. Often Scriptlistener steps are turned is to functions used in Photoshop scripts to be able to things that are impossible using Adobe's Photoshop DOM.

                 

                Adobe Photoshop installer also installs "ExtendScript Toolkit" in addition to Photoshop and the Bridge.  This Tool for editing and debug scripts. I also contains an object viewer.  It seems to be the only place you can find out what in an Adobe Photoshop object.

                 

                The best place to learn about scripting Photoshop is here and http://www.ps-scripts.com/  I have never found any book on scripting Photoshop only Adobe's scripting guides.  You also need to learn the Javascript language.  The book with the rino on the cover. Someday I may buy it.  I just hack script code I find on the web most is somewhat readable after a while..  I cut and paste for I can not type..

                • 5. Re: Is it worth it for me to learn scripting in PS?
                  Michael L Hale Level 5

                  The scriptlistener plug-in and Action Manager are things I would list in the 'learn when you need them' category. You will likely need it at some point but wait until then. You can write very functional script without Action Manger.

                   

                  The Object Model Viewer in ExtendScript Toolkit is helpful. But the javascript ref.pdf has more details and fuller explanations. So it's not the only( or best ) reference. The viewer might be of some help as it also has the core javascript classes including file and folder classes. And the ScriptUI classes. But the javascript tools guide has more detail about those classes as well as BridgeTalk,XMP, and XML I think the most useful thing about the viewer is it has almost everything in one place. even if it is short on details.

                   

                  Most books I have seen on javascript spend most of the time talking about the browser DOM. Which is fine if you also want to script web pages. But for just Photoshop scripting I think you should avoid them so you will not be confused by all the DOM explanations that will be of no help.

                  • 6. Re: Is it worth it for me to learn scripting in PS?
                    xbytor2 Level 4

                    More tips:

                     

                    Your first set of scripts should not use any UI. ScriptUI has a learning curve that you should put off initially. You can use the File and Folder classes for prompting for files to open or save, but don't build any of your own windows. If you do need to change settings between runs of a script, use a global variable in which you store those settings. Edit the script to change them as needed.

                     

                    Then you can learn ScriptUI or ActionManager next, as needed.

                     

                    Use ESTK as your javascript editor unless you already have a preferred programming editor.

                    • 7. Re: Is it worth it for me to learn scripting in PS?
                      JJMack Most Valuable Participant

                      Yes I agree I only use the ExtendScript Toolkit Object explorer to learn what fields are in objects.  I have trouble using it for debugging because of the way window contents jump about and some of my script that work don't work within it.  I'll sometime use its editor  to see its syntax highlighting help me find typos, find missing brackets and tidy up my code. Most of my debugging is done by adding alerts statement to check on things. These alerts are later removed or commented out.

                       

                      Also Adobe's scripting guides is the only books the document their Photoshop DOM however it lack some information which can be found in the toolkit's viewer. The viewer also  has basic system object used for using your OS file system  which you may want to use these objects are not in Adobe guide the are part a javescript.  Also because your using javascrip dont forget about web searches often you need information about javascript. Search the web.  Some day I may buy the javascrpt rino book.

                      • 8. Re: Is it worth it for me to learn scripting in PS?
                        spdorsey6969 Level 1

                        Mike,

                         

                          We are using CS5 at work because CS6 and CC have changed the way masks are handled. So older sources of info might pertain.

                        • 9. Re: Is it worth it for me to learn scripting in PS?
                          spdorsey6969 Level 1

                          xbytor2,

                           

                            I use BBedit when I code HTML/CSS. I'm fairly sure that it also has Javascript tools. Would this be a good tool to use to create/edit JS?

                           

                          Thanks

                          • 10. Re: Is it worth it for me to learn scripting in PS?
                            Michael L Hale Level 5

                            With CS5 the javascript ref and the javascript tools guide are already on you system. Along with some sample scripts.

                            • 11. Re: Is it worth it for me to learn scripting in PS?
                              xbytor2 Level 4

                              BBedit will be fine. I tried it out years ago, used it a bit, and liked it. Then I found a reasonable emacs port and never looked back.

                              • 12. Re: Is it worth it for me to learn scripting in PS?
                                JJMack Most Valuable Participant

                                If your like me you don't want to write script that can be done with an action for actions are easy scripts are not why write that script. You want to automate thing that can not be automated with an action.  The first scripts I ever wrote were little simple Photoshop functions to be used in action.  To enhance what an actions can do. 

                                 

                                Then I wanted to be able to mark a document given its current state then change maybe change that state in an action then later the action could run a script that may use the mark to do something logical. I found a script on the web though it had bugs. It was designed to do what I wanted to do and I had no problem fixing the bugs in its design and coding. Its basic design was all I needed.

                                 

                                Then I wanted to be able to pass a scripts some parameters but the was impossible back in CS2.  Then in CS3 Adobe introduced Plug-in support into Photoshop scripting. In fact Adobe converted their compiled automate plug-in Fit Image source code to javascript and that used the new scripting plug-in support. It was now possible to create actions that pass parameters to a script.

                                 

                                Writing a plug-in script is beyond my scripting ability. However modifying an existing Plug-in script is right up my alley.  I striped out Fit Images resize fuction and added functions I needed and I added more fields to the dialog for parameters I wanted to be able to have actions pass.

                                 

                                The problem I ran into was the function I wanted to add was not possible using Photoshop's DOM.  Then I discovered the Scriptlistener Plugin and realized all those scripts that I had downloaded and could not read well was because they were using Scriptlistener code to pull off some Action Manager steps. 

                                 

                                If you download my crafting actions package it contains a dozen of my first scripts.  Because I was new at scripting I tried to to make them readable and I updated them as I learned more about scripting.  There are three types of scripts in there. Some simple Photoshop function.  Some that are run twice in actions sort of a save and restore function for actions. There are also two plug-in scripts.

                                 

                                • 13. Re: Is it worth it for me to learn scripting in PS?
                                  spdorsey6969 Level 1

                                  We ar eusing CS5. Have there been significant changes to the way scripting works in CS6/CC?

                                  • 14. Re: Is it worth it for me to learn scripting in PS?
                                    JJMack Most Valuable Participant

                                    I can not answer about CC. There were big changes made to scripting in CS2 and in CS3 Plug-in was added and that was update in CS4.  Michael, The now missing Paul, and X know more about scripting and may be using CC however CC is why Paul left here...

                                    • 15. Re: Is it worth it for me to learn scripting in PS?
                                      spdorsey6969 Level 1

                                      CC caused someone to leave the forums? Is it THAT bad?

                                      • 16. Re: Is it worth it for me to learn scripting in PS?
                                        Michael L Hale Level 5

                                        There are some changes with CS6 and CC. Mostly either bugs or bug fixes. CC does have some new scripting features. But all versions since Photoshop 7 have some scripting bugs and new features. Those differences can be a problem if you are writing a script that for others that needs to work in multiple versions. But if you are writing for yourself you only have to worry about the bugs and feature support for your version.

                                         

                                        I think Paul, like others, is frustrated by some of the bugs( especially in ScriptUI in Paul's case ) and Adobe's seemly lack response to scripting bugs and feature requests. But as far as I know he has not 'left' because of Photoshop CC. He made a post on this forum just a few weeks ago. I suspect his lack of activity has more to do with the summer holiday season in England. At least I have not seen a post from Paul either here or at PS-Scripts where he said he was giving up on Photoshop scripting because of CC.

                                        • 18. Re: Is it worth it for me to learn scripting in PS?
                                          DBarranca Level 4

                                          Michael,

                                          do you happen to have a list of the CC new features?

                                          Thanks,

                                           

                                          Davide

                                          • 19. Re: Is it worth it for me to learn scripting in PS?
                                            Michael L Hale Level 5

                                            No, I don't have a list of new features. And I was grouping CS6 and CC together. When I last checked Adobe had not made the CC scriptig ref available to download yet. I do know that Photoshop CC artlayer action descriptor has a new key that will let you get the bounds of the layer without any layer effects. So you no longer have to turn off the layer effects to get the true layer bounds.

                                             

                                            And the tab document view / document focus loss bug seems to be fixed.

                                             

                                            On the downside( at least on my system ) code hinting in ESTK doesn't work when CC is the target app unless I target Photoshop CS6 at the start of the ESKT session. I guess doing that 'loads' the code hinting for Photoshop and ESTK still uses that when I switch to CC. But if I start a ESKT session and never have CS6 as the target app the code hinting only has core javascirpt and ScriptUI properties and methods.

                                            • 20. Re: Is it worth it for me to learn scripting in PS?
                                              Zetta Level 1

                                              Mike, 

                                              I've noticed this with the ESTK on my system as well.  Its very annoying. And I too am waiting for the CC scripting ref to be available... why isn't it?

                                              As a person who scripts alot by getting ID strings from scripting listener to use with Action Manager code...  I keep finding more and more things that do not record in CC.

                                              I'm getting errors in my actionManager code that I don't get in cs applications.   The issues are starting to pile up.   

                                               

                                              for example: you can't record any filter actions in CC?

                                              • 21. Re: Is it worth it for me to learn scripting in PS?
                                                JJMack Most Valuable Participant

                                                Since CS4 new code from Adobe has been buggy you need to get use to that. Personally I'm fed up with Adobe introducing more and more new bugs. I'm staying with CS6 where I know where the bugs that effect my work are and I can circumvent all but the occasional CS6 crash.  Adobe releases code before its ready for general consumption. Documentation is messed up and things are mising...

                                                • 22. Re: Is it worth it for me to learn scripting in PS?
                                                  Zetta Level 1

                                                  I hear ya.  I keep a version of CS3 on my computer just for the great scripting listener feedback.  CS3 will kick out actionmanger codes I cant find anywhere else.  Its an essential.

                                                  • 23. Re: Is it worth it for me to learn scripting in PS?
                                                    JJMack Most Valuable Participant

                                                    Yes CS3 was the last good version of Photoshop Adobe released. I'm sure there are bugs in CS3 however CS3 at least works in a consistent manner.  If you do not change Adobe's default setting in the Adjustment Panel Adobe added to newer versions of Photoshop  fly-out menu  . Photoshop will operate in a mode that is compatible with prior versions of Photoshop and the newer versions will operate in a consistent way.  There are bugs with two of the options in the Adjustment Panel Fly-out menu.  The options do not always work and they are incompatible with some actions, script and - created for Photoshop for sometime the change Photoshop default operation.  They were design to change Photoshop default operation however they don't always. Changing Photoshop default operation breaks will break some Actions, Scripts and plug-ins.  

                                                     

                                                    When coding you need to write the code to use the options you want to use.  When there are no options there are no option to code for. If later there are options for an operation. Previous code the used that operation may need be updated.  In the past when you added an adjustment layer and layer mask was always included. It the is now an option and if one set that option and no layer mask is added. If an old Action, Script or Plug-in added an Adjustment layer then later modified its layer mask they will  fail for there is no layer mask to modify unless there was an active selection when the Adjustment layer was added for even though the option is set not to add a layer mask a layer mask containing the active select will still be added.  Adobe must have done away with code testing and design verification.

                                                     

                                                    Message was edited by: JJMack

                                                    • 24. Re: Is it worth it for me to learn scripting in PS?
                                                      Michael L Hale Level 5

                                                      photospot_scripter wrote:

                                                       

                                                      for example: you can't record any filter actions in CC?

                                                      I have not run into anything that will not record in Photoshop CC that would record in earlier versions. I think the only advantage use CS3 for scriptlistener logging is that version is the last pre-adjustment panel version. So it is slightly better for recording adjustments. But I am unaware of CS3 recording anything that you can't record in later versions.

                                                      • 25. Re: Is it worth it for me to learn scripting in PS?
                                                        Zetta Level 1

                                                        For Example: Here's a specific one that is causing some of my tools to no longer work.

                                                         

                                                        Liquify.  Scritping listener results when you load a previously saved mesh into the Liquify Filter:


                                                        in CS6 (version 13.0  x64) :

                                                        // =======================================================

                                                        var idLqFy = charIDToTypeID( "LqFy" );

                                                            var desc2 = new ActionDescriptor();

                                                            var idLqMe = charIDToTypeID( "LqMe" );

                                                            desc2.putString( idLqMe, """X:\example\exportMeshs\testMesh_10.msh""" );

                                                        executeAction( idLqFy, desc2, DialogModes.NO );

                                                         

                                                         

                                                        in CS6(version 13.1.2  x64)  and CC.

                                                        // =======================================================

                                                        var idLqFy = charIDToTypeID( "LqFy" );

                                                        executeAction( idLqFy, undefined, DialogModes.NO );

                                                         

                                                         

                                                        What happens when you run the 13.0 code in the 13.1 or 14?

                                                             CS6 13.1.2 = CRASHES!! (buh bye)

                                                             CC 10.0 = Ignores called mesh, and always uses last loaded mesh. = fail.

                                                         

                                                        And thats just the most annpying one, as I have tools out there for clients that use a scripted liquify call.   and their tools have stopped working.

                                                        • 26. Re: Is it worth it for me to learn scripting in PS?
                                                          Michael L Hale Level 5

                                                          I was unaware of that. I don't use the liquidy filter much. And I misunderstood you when you said that "you can't record any filter actions in CC". Most filters are still recorded by scriptlistener, including liquify( granted CC doesn't record loading or save the mesh ).

                                                           

                                                          I think this is more of an example of how a new feature can break scripts written for older versions. I think the problem is with the changes made to the liquify filter so it can be used as a smart filter. Even older liquify actions may not work in CC.

                                                          • 27. Re: Is it worth it for me to learn scripting in PS?
                                                            JJMack Most Valuable Participant

                                                            Adobe make changes in each release of Photoshop.  I never created any complex scripts thill CS2.  In CS2 I had to code around a scripting bug I think selection bounds did not work. When CS3 was released my script still worked. Cs4 I skipped but received reports my scripts were failing. When I installed CS5 I was able to code around the Bug introduced in CS4 my second Place operation failed because the current target was the layer mask I added to the last placed layer.  The message was Place not currently available. Is was in prior release of Photoshop and also in the current release in actions and manual mode only invalid in scripting.  CS5 also changed how Layer mask work on Smart Object layers. In prior version they could not be linked with the smart object.  In CS5 they were added linked by default so I had to modify my scripts that add layer mask to un-link them. CS6 also added a scripting bug.  Bicubic Automatic support was not added. When a script retrieved Photoshop interpolation preference when its Bicubic Automatic Photoshop fails with an internal error.  As I wrote you have to get use to the fact that ever release of Photoshop will have issues or do what I'm doing which is staying with CS6.

                                                            • 28. Re: Is it worth it for me to learn scripting in PS?
                                                              Michael L Hale Level 5

                                                              photospot_scripter,

                                                               

                                                              This seems to work in CC

                                                               

                                                              var meshFile = new File('~/desktop/Liquify.msh');
                                                              
                                                              meshFile.open('r');
                                                              meshFile.encoding = 'BINARY';
                                                              var desc4 = new ActionDescriptor();
                                                              desc4.putData( charIDToTypeID( "LqMe" ),meshFile.read());
                                                              meshFile.close();
                                                              executeAction( charIDToTypeID( "LqFy" ), desc4, DialogModes.NO );
                                                              

                                                              And it works with both a normal artLayer or as a smart filter.

                                                              • 29. Re: Is it worth it for me to learn scripting in PS?
                                                                Zetta Level 1

                                                                ahh!  I never tried converting it to Binary.  I'll try it out.

                                                                 

                                                                The more I script the more I realize how powerfull that Action Manager stuff is.  I'm trying to master it....as its so much faster then the DOM  and you can do many more things.   But I'll be the first to admit I'm holding on to tightly to my Scripting Listener crutch.

                                                                 

                                                                Here are my last 2 cents. :  "Is it worth it for me to learn scripting in PS"?  I would say yes.  Read the documentation, get to know the tools, search the forums and you'll be rewarded. I've been doing this for 10+ years, and still love that powerfull feeling when you can sit back and watch Photoshop do the work for you. 

                                                                 

                                                                Thanks again Mike, you've helped so many.