11 Replies Latest reply on Jun 23, 2010 9:00 PM by Michael L Hale

    JS CS4 & CS5 working through the ScriptListener

    John.Kordas

      Working through the guide there is an example:

      var eventFile = new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx")
      app.notifiers.add( "Opn ", eventFile)

       

      There is 2 possible places to save this file in windows:

       

      C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts

       

      or


      C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts\Event Scripts Only

       

      I've tried both and when I open a file in Photoshop I do not get the alert.

       

      If I go into the Script Event Manager and set the above code to run on Open Document event it works.

       

      Is there a way to get this example to work without setting it up in the Script Event Mananger?

       

      Cheers.

        • 1. Re: JS CS4 & CS5 working through the ScriptListener
          xbytor2 Level 4

          Open ESTK

          Open a new file

          Copy your code to the file

          Set the debug target to PS

          Run the code with the debugger's Play button

           

          Or save the code to a JSX file and run it  via File > Scripts > Browse or from within ESTK as described above.

           

          -X

          • 2. Re: JS CS4 & CS5 working through the ScriptListener
            Tom Ruark Adobe Employee

            Odd, running the script from ESTK does not work but appears to do the right thing. Running it via drag/drop and it works correctly. You need to add the following line to your script.

             

            app.notifiersEnabled = true;

            1 person found this helpful
            • 3. Re: JS CS4 & CS5 working through the ScriptListener
              John.Kordas Level 1

              Thanks Tom it sort of works,

               

              If I run the line app.notifiersEnabled = true; in the ESTK then it works fine. I set it back to false and add the code to the script, restart PS and still nothing.  I've tried placing the script in just the scripts folder and in just the Event Scripts Only but with no luck.

               

               

              Is there a way to run the app.notifiersEnabled = true; without having to run it in ESTK?

               

               

              app.notifiersEnabled = true;
              var eventFile = new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx");
              app.notifiers.add( "Opn ", eventFile);

              • 4. Re: JS CS4 & CS5 working through the ScriptListener
                xbytor2 Level 4

                IIRC, if you use the API to register a notification, it only lasts the duration of that PS session. You have to run it each time you run PS or you need to use the Scripts Event Manager.

                 

                It doesn't matter where the file is located as long as it matches the path that you specify.

                • 5. Re: JS CS4 & CS5 working through the ScriptListener
                  John.Kordas Level 1

                  Thanks xbvtor2,

                   

                  I did notice that app.notifiersEnabled = true; turns on the Script Event Manager. So if I was to place that code in the scripts folder should it not automatically enable the Script Event Manager every time I start PS?

                   

                  I'm losted as to why even through I've put the app.notifiersEnabled = true; line in the code the SEM does not get enabled. The path is correct because when SEM is enabled the alert works every time. I also noticed that even though I ran the line in the ESTK if I restarted PS it was still enabled.

                   

                  Cheers, John.

                  • 6. Re: JS CS4 & CS5 working through the ScriptListener
                    Michael L Hale Level 5

                    My experence is that you only need to set app.notifiers.enabled to true if it is not already set. It can be set to true by a script or the Scripts Events Manager.

                     

                    If you register an event using app.notifiers.add in ESTK the event does not run the script unless Photoshop is restarted. If it is added as part of a script run in Photoshop or the Script Events Manager it runs without restart.

                     

                    As X pointed out the scirpt can be anywhere, it doesn't have to be in one of those two locations. But for me events registered with the API remain registered from session to session untill removed.

                     

                    Here is a save way to register an event. Note that it only sets app.notifiers.enabled to true if it is false and registers the open event only if there is not already one.

                    if(!app.notifiers.enabled) app.notifiers.enabled =  true;
                    var hasOpenEvent = false;
                    for(var e = 0;e<app.notifiers.length;e++){// the only way to tell which events are in use is to loop notifiers
                         if(app.notifiers[0].event == 'Opn ') hasOpenEvent = true;
                    }
                    if(!hasOpenEvent) {
                         var eventFile = new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx");
                         app.notifiers.add( "Opn ", eventFile);
                    }
                    

                    And as I understand it

                    new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx");

                    will only work with English versions of Photoshop.

                    • 7. Re: JS CS4 & CS5 working through the ScriptListener
                      xbytor2 Level 4
                      But for me events registered with the API remain registered from session to session untill removed.

                       

                      I may have been doing something wrong when I originally tried this. It wasn't what I needed anyway since I only wanted the notification registered for the session and wrote a bunch of code to auto-register/deregister the script.

                       

                      And as I understand it

                      new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx");

                      will only work with English versions of Photoshop.

                       

                      I checked serveral European and Asian language installs that I've got and none of the paths below Presets are localized. The Samples and Scripting Documentation folders are, however.

                      • 8. Re: JS CS4 & CS5 working through the ScriptListener
                        John.Kordas Level 1

                        Thanks Michael,

                         

                        I must be missing somthing. I tried your code was was not able to get it to work. I thought I'd take it one step back and tried:

                         

                        if(!app.notifiers.enabled) {
                            alert("true");
                            app.notifiers.enabled =  true;
                            }else{
                                alert("false");

                         

                        Placed this in the scritps folder got nothing. Ran it from the ESTK and keeped getting true.

                         

                        So I change app.notifiers.enabled to app.notifiersEnabled and still got nothing when PS starts but if I run it in the ESTK i'll get true then false etc.

                         

                        if(!app.notifiersEnabled) {
                            alert("true");
                            app.notifiersEnabled =  true;
                            }else{
                                alert("false")

                        • 9. Re: JS CS4 & CS5 working through the ScriptListener
                          John.Kordas Level 1

                          After a bit of searching on the web I found C:\Program Files\Common Files\Adobe\Startup Scripts CS5\Adobe Photoshop.

                           

                          I place the following code in there:

                           

                          if(!app.notifiersEnabled) {
                              app.notifiersEnabled =  true;
                              }

                           

                          This seems to work but as the info I found stated every time you run a script this code is executed. So if I try and disable ESM it automatically comes back enabled.  I could be wrong but I gather that scripts in the C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts do not automatically execute and this might be due to security issues. I have found that I have to select them via the File/Scripts menu in PS.  If anyone is aware if this is the case I'd be grateful for the confirmation.

                          • 10. Re: JS CS4 & CS5 working through the ScriptListener
                            xbytor2 Level 4
                            I could be wrong but I gather that scripts in the C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts do not automatically execute

                             

                            That is true. File > Scripts is how those are executed. If you want a script to run everytime PS launches, look for:

                             

                               On WinXP CS2
                                  %CommonProgramFiles%\Adobe\StartupScripts
                               On WinXP CS3
                                  %CommonProgramFiles%\Adobe\Startup Scripts CS3\Adobe Photoshop
                               On WinXP+ CS4
                                  %CommonProgramFiles%\Adobe\Startup Scripts CS4\Adobe Photoshop
                               On WinXP+ CS5
                                  %CommonProgramFiles%\Adobe\Startup Scripts CS5\Adobe Photoshop

                             

                            %CommonProgramFiles% is usually equivalent to something like:
                                C:\Program Files\Common Files\

                            • 11. Re: JS CS4 & CS5 working through the ScriptListener
                              Michael L Hale Level 5

                              xbytor2 wrote:

                              I checked serveral European and Asian language installs that I've got and none of the paths below Presets are localized. The Samples and Scripting Documentation folders are, however.

                              That is good to know. In my notes I have several ZStrings for folders. I guess becuse I found ZStrings I thought they were localized.

                               

                              "$$$/ScriptingSupport/InstalledScripts=Presets/Scripts"
                              "$$$/private/Plugins/DefaultPluginFolder=Plug-Ins"
                              "$$$/ApplicationPresetsFolder/Presets=Presets"
                              "$$$/private/FolderName/UserPresetsFolder/Presets=Presets"