2 Replies Latest reply on Aug 28, 2013 1:36 PM by myscreennameis_Miles

    Can't find an application close event.

    myscreennameis_Miles Level 1

      I have a script that runs on the document close event.  It looks like the document close event doesn't fire when the application is closed while a document is open. I checked for an application close event in the Script listener log, but there wasn't an entry for it, and the document close event wasn't present either.

       

      The script I'm making writes a file in the same folder as the opened document that indicates that the file is in use. Then when the document is closed, the lock file is removed.  It works except when you close the application.  There is no document closed event firing, so the documents just close and the application shuts down without any events firing.

       

      Is there a way know when the application is closing?

       

      I found a possible work around that would be a huge pain.  The idea is about loading a custom external library that performs cleanup when it is automatically unloaded when Photoshop closes.  This is the prototype for the function that would do the work:

      void ESTerminate (void );

       

      There is another work around that invloves some button that the user has to remember to click to close the application. That would be awkward and open to user error.

       

      I just want the document closed event to fire before the application closes. Thanks for you help!

        • 1. Re: Can't find an application close event.
          Michael L Hale Level 5

          Event handlers in Photoshop are called after the event with normal javascript scripts. There isn't a close event because Photoshop is already closed so can't call the handler. And javascript runs with Photoshop as the host app so the event handler is destroyed when Photoshop closed.

           

          You might want to look at writing an extension using the CS-SDK. At one time they were planning to offer both  before and after event handlers.

          • 2. Re: Can't find an application close event.
            myscreennameis_Miles Level 1

            That's too bad.  I don't feel like getting a whole build environment setup for CS just so I can get a pre-close event in Photoshop.  I implemented a script that the user will run in order to close photoshop. I saved a shortcut to the script in "C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)\Presets\Scripts".  The script closes each document and runs my event handler. Then it exits. Check it out, it seems to work:

             

            #target photoshop
            //user will run this script instead of hitting exit button

            var MLAB_CUSTOM = new Folder($.getenv('MLAB_CUSTOM')).absoluteURI
            var docs = app.documents

            for(var i = docs.length-1; i >= 0; i--)
            {
            docs[i].close()
            $.evalFile(MLAB_CUSTOM+"/Ps-FileLock/PsLock-OnDocClose.jsx")
            }
            photoshop.quit();