Skip to main content
shelbycott
Known Participant
July 5, 2020
Answered

In-script event listener for save event

  • July 5, 2020
  • 2 replies
  • 2652 views

Unfortunately I think I already know the answer to this, but is it possible to add an event listener to a save event that runs while Extendscript is being executed (something similar to beforeSave in InDesign)? I'm attempting to prevent the default action, run additional code, then proceed.

 

I already attempted to do this with app.notifiers but the file doesn't run until my script is complete. I'm curious if there's possibly some way to do this with Action Manager.

 

Thanks so much!

This topic has been closed for replies.
Correct answer JJMack

I do think you do know the answer that event are only triggered from Photoshop UI after the event has completed.   Event are not triggered during an automated Process. Actions, Scripts, Plug-ins.  I always wondered what one could do in a close event handler. There may be nothing in Photoshop what would a close event handler be good for?

2 replies

Legend
July 6, 2020

You can track the 'save' or 'All ' event if it is being executed by the user. When saving a file, there are also separate notifications for the save steps, ("saveBegin" and "saveSucceeded"), but since the notification comes after the action is completed, by the time the notification “saveBegin” is received, the saving process will already be started

 

 

#target photoshop
try { var target = arguments[0], event = arguments[1] } catch (e) { }

try {
    if (!target) { // main script code
        var d = app.documents.add()
        app.notifiersEnabled = true
        app.notifiers.add('All ', File($.fileName))
    } else { // event triggering
        var t2s = typeIDToStringID,
            s2t = stringIDToTypeID;
        if (t2s(event) == 'save') {
           alert(t2s(target.getEnumerationValue (s2t('saveStage'))))
        }
    }
} catch (e) { alert(e) }

 

JJMack
Community Expert
JJMackCommunity ExpertCorrect answer
Community Expert
July 5, 2020

I do think you do know the answer that event are only triggered from Photoshop UI after the event has completed.   Event are not triggered during an automated Process. Actions, Scripts, Plug-ins.  I always wondered what one could do in a close event handler. There may be nothing in Photoshop what would a close event handler be good for?

JJMack
Legend
July 6, 2020

I always wondered what one could do in a close event handler.

 

For example, open the following file.

Legend
July 6, 2020

r-bin

What file would thet be can you tell what file was closed so you use logic to figure out the next file. If its using  a file list log.  Does it check if a previous file it opened is still an open document that the document closer was not related to the list.  I'm not stating you can not code a close event handler I just do now know what I could find it useful to do becaus of my knowledge.   Can it fnd out what document was closed by the close event it is no longer in Photoshop. It histort states also no longer exist many files could have bees saved form the docoment.  The backing file mays or may not have be updated.  What inforatiom can be retieved about the closed document event?.  You know how Photoshop works way better then I do and, you how to retrieve information using Action Managers code and know how to find out what information may be  available.  You also know Java script well your knowledge is well above the Adverage Photoshop User, Above Good Photoshop users High above my knowledged.  Have you ever coded a Close event handler.  You are one of the expert Scripter here.  I just do some hacking here and there. I can not even type.


I wrote such scripts.
Tracking the closing of a document makes sense when the user wants to manually process a group of files in sequence. That is, when, on the one hand, you need to work with a list of files, and on the other, there is no way to control user actions during processing. This is very convenient - the script opens the file, the user works with it (while working, it can freely open and close other documents), closed it and immediately opens the next one from the list (you can track which file was closed, because in the body of the event ID is transmitted)
I also wrote a script to track the time of manual processing of files (the time interval between opening and closing a document was monitored)