• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

In-script event listener for save event

Explorer ,
Jul 05, 2020 Jul 05, 2020

Copy link to clipboard

Copied

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!

TOPICS
Actions and scripting , SDK

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 05, 2020 Jul 05, 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?

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 05, 2020 Jul 05, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 05, 2020 Jul 05, 2020

Copy link to clipboard

Copied

Darn, I figured. Thanks for confirming!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2020 Jul 06, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jul 06, 2020 Jul 06, 2020

Copy link to clipboard

Copied

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

 

For example, open the following file.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2020 Jul 06, 2020

Copy link to clipboard

Copied

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.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 06, 2020 Jul 06, 2020

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2020 Jul 06, 2020

Copy link to clipboard

Copied

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.....

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 06, 2020 Jul 06, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 06, 2020 Jul 06, 2020

Copy link to clipboard

Copied

LATEST

You would need to track way more then close as far as I know.   Open event  and new document events  to know when file are open and new document are add into Photoshop. If I create a new document and immediately closet it how does the close event handler know anything about the closed document?  I asked can any information  about the closed document be retrieved by the event handler its not in photoshop when the close event  handler start it execution?  How is information passed  I was not aware that event handlers have message  or parameters pass to it by Photoshop. 

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Jul 05, 2020 Jul 05, 2020

Copy link to clipboard

Copied

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) }

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines