11 Replies Latest reply on Aug 4, 2017 10:46 AM by extendersGame

    Exiting photoshop from a jsx script

    RichardMunn

      I've written a jsx script which performs a set of automated testing operations for a plugin I'm writing.

       

      The intention is that it spits out a folder full of PNGs that I can then externally examine to make sure its functioning as it should.

       

      The biggest problem I've got now is that I can't find a way in Javascript to quit the Photoshop application when I'm done.

       

      (I know VBS has a quit function, but rewriting my script into VBS isn't really an option, unless there's a way I can run VBS code from within my JSX script?)

        • 1. Re: Exiting photoshop from a jsx script
          c.pfaffenbichler Level 9

          var idquit = charIDToTypeID( "quit" );

          executeAction( idquit, undefined, DialogModes.ALL );

          • 2. Re: Exiting photoshop from a jsx script
            RichardMunn Level 1

            Thanks - that's getting me closer to where I need to be :-)

             

            On a related question, is there a way to supress the "You should only run scripts from a trusted source" message box that pops up when you externally launch a .jsx file?

            • 3. Re: Exiting photoshop from a jsx script
              RichardMunn Level 1

              Never mind - just discovered I can run the PS exe directly with my script as an arg and it appears to work fine :-)

              • 4. Re: Exiting photoshop from a jsx script
                runninghead Level 1

                Care to share RichardMunn?

                • 5. Re: Exiting photoshop from a jsx script
                  xbytor2 Level 4
                       photoshop.quit();
                  

                   

                  if you want to keep things simple...

                  • 6. Re: Exiting photoshop from a jsx script
                    mangalarajiv

                    Hi,

                     

                    Is there possible to Start the application or open the application through scripting?

                     

                    Could you please let me know.

                     

                    thanks,

                    rajiv,s

                    • 7. Re: Exiting photoshop from a jsx script
                      yajiv_viki Level 2

                      Hi rajiv

                       

                      Check this code.

                       

                      #target photoshop

                      app.bringToFront();

                       

                       

                      - yajiv.

                      • 8. Re: Exiting photoshop from a jsx script
                        mangalarajiv Level 1

                        Hi yajiv,

                         

                        It' working greatly.

                         

                        thanks,

                        rajiv.s

                        • 10. Re: Exiting photoshop from a jsx script
                          Kukurykus Adobe Community Professional

                          runninghead I know what  RichardMunn meant. You can create txt file by a Ps script, where you put ex. code:

                           

                          cde = '"C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)" d:\someScript.jsx'
                          tmp = File('~/Desktop/Tmp.txt'), tmp.open('w'), tmp.write(cde), tmp.close();
                          

                           

                          then you rename it by Ps script to someScript.bat, and finally you execute it. This way you omit that warning:

                           

                          File('~/Desktop/Tmp.txt').rename('Tmp.bat'), File(Tmp).execute()
                          

                           

                          Of course if you don't want to put your scripts to "C:\Documents and Settings\Administrator\My Documents\Adobe Scripts" folder or run it directly from Photoshop (when your scripts are in Photoshop/presets folder you can't just double click your script. You must either do it by command line (the same as clicking right mouse button on the script file to choose 'open with' and then select Photoshop), or if you call some script by external executer (when your script is not in secure source) you can do it the way I described at beggining.

                           

                           

                          That code at top what's put to notepad in order to change it then to batch file, means that you want to open someFile.jsx which you see in second part of that code (so it's a like an argument), in the application (Photoshop) you see in first part of that code.

                           

                          There should be possible to do that by app.system('"C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)" d:\someScript.jsx') but unfortunatelly that doesn't work, though when I tried something simpler like system(notepad d:\someText.pdf') there wasn't a problem. (yes, I wrote .pdf to open as .txt as this example came to me as similar to open .jsx not by extendscript but a photoshop).

                           

                          I was smart and did something like it:

                           

                          system('"' + app.path.fsName + '\\photoshop.exe" ' + File($.fileName).fsName)
                          

                           

                          well it worked but some strange way. It opened Command Line window, not for max a second though like it happens most often, but for longer to get stuck untill you closed it manually. Then the script started working (you can try with some simple alert('Hello')). When I tried to run it again Photoshop stopped working and some error popped up that I had to quit photoshop and open again. I repetead it few times and always that was like before. The same error forcing me to reopen Photoshop. Too bad. Fortunatelly I always can do that I put by a script everything to a text, to save as text and change to .bat, to run it when I want (see beggining of this post).

                           

                          This is very good method if you want to run all scripts you'd like to supress harrasing security window, and you don't want to change all your scripts to be always opened directly by Phoptoshop (possible by changing default appliccation in properties of file), as they appear then with Photoshop.exe icon and the first application to run any script (even if there is #target extendscript) will be Photoshop.

                           

                          There is other method with shortcut, but I hope the one in this long post will be sufficient for anyone having same problem.

                          • 11. Re: Exiting photoshop from a jsx script
                            extendersGame Level 1

                            I believe he is referring to running a command line command along the lines of:

                            start "" photoshop.exe PathToScript\ScriptName.jsx

                            which will launch the file without a prompt.