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

In-script event listener for save event

  • July 5, 2020
  • 2 replies
  • 2658 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

You seem the see the same Problems  I see you can not control the users for sure. Were you able to retrieve information  about document that was just close no longer open in Photoshop like was is a new document that was never saved so its gone forever for the was never a file saved from it.....


I do not fully understand what is bothering you. We can receive and save all the necessary information about the document at any time before it is closed - for this it is enough to set notifications for the intermediate stages of processing.
As arguments, when an event occurs, the script always receives enough information to understand which document and processing stage they relate to. If you wish, you can track all user actions from the moment of opening (creating a document) to the moment of closing (saving) - approximately the same as it happens when recording actions.