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

In-script event listener for save event

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

Brainiac
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
JJMackCorrect 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
shelbycott
Known Participant
July 6, 2020

Darn, I figured. Thanks for confirming!

JJMack
Community Expert
July 6, 2020

You can tract all save and save as events the users does from Photoshop UI  the current document is still open.  I believe you would need retrieve how Save As was used though,  Where to, File name, File type Save is straight to the backing file.  There is a start Save event that may be what you want to use you may need to use both for there does not seen to be as separate event for Save AS,  The user may start a save as then cancel and a "Save" is a done deal there no dialog no chance to cancels save.  Where Save As has a Dialog Photoshop can trigger the Start save when you click Save/Cancel  before doing the buttons action .  Where you created and maintain the log is up to you the event will be triggered for all documents. I have never coded a saver event handler.

JJMack