Properly intercepting the Audition document save event

In my last post, I talked about the development of my Notes Panel for Adobe Audition extension and all the issues I ran into.

The issue I was stuck on for the longest time was intercepting the event for when a user saved the current document. I never figured out the proper way and instead came up with a more hacky way of doing it using Extendscript. But since then I have with the help of some awesome Audition developers figured out how to get the event to work! And I intend to share it with you in this post.

But first, let’s explain what should work and how I got it to work in the
extension initially.

CEP extensions along with Extendscript have events that you can intercept,
Extendscript has a lot, and most of them are unique to each app. CEP has a few of its own that is shared between applications, like opening a document, saving a document, changing the active document, etc. Some of the Adobe apps support all of them while others just support a few of them, heck some don’t support them at all. This is all documented in the CEP cookbook. But as I mentioned in my last post the event for saving a document never fires, and if it does, it’s impossible to intercept it.

CEP Events from the CEP 8 Cookbook

So how did I circumvent this issue in my extension then?

By making my own event of course. Adobe provides an Extendscript library called PlugPlugExternalObject which among other things allows you to create custom CEP events that can then be intercepted using the CSInterface like a normal CEP event.

Here’s an example of creating such an event similar to what I did in the Notes Panel extension

In Extendscript:

function addDocumentListener() { app.activeDocument.addEventListener(DocumentEvent.EVENT_SAVED, documentSaved); //Adds an extendscript event listener for Audition's save event. 
function documentSaved(event) { // Creates a custom CEP event that is fired once the extendscript event is intercepted. 
var csxsEvent = new CSXSEvent(); 
csxsEvent.type = "DocumentSaved"; 
csxsEvent.data = "Audition Document Saved!"; 
csxsEvent.dispatch(); }

In the extension's Javascript file:

csInterface.evalScript("addDocumentListener()"); // Run the extendscript code for adding the event listener. 
csInterface.addEventListener("DocumentSaved", function (event) { // Intercept our custom CEP Event. console.log("Document Saved!"); })

This works, but it has a few unintended side effects:

  1. Since the notes are saved as metadata Audition detects changes to metadata immediately after saving the document, leading to the dreaded “Unsaved changes” Asterisk being present at all times when using the panel.
  2. Going trough Extendscript and then through the CEP API’s adds more points of failure and while I have not done any tests it’s possible this approach might take longer than a more native CEP event would.

So what is the proper way to do it then? After talking to a few Audition
developers, I finally know the answer: Audition has a different name for the
DocumentAfterSave event as it uses DocumentSaveAs instead, the event
functions in the exact same way as it does in other apps, it’s just named
differently. Here’s an example using the proper event:

var csInterface = new CSInterface(); csInterface.addEventListener("com.adobe.csxs.events.DocumentSaveAs", function (event) { console.log("com.adobe.csxs.events.DocumentSaveAs"); });

It’s really that simple but with no actual documentation even mentioning this
event existing, one can hardly blame me or anyone else for not figuring it out on their own, unless you’d try every conceivable name for a save event.

It also turned out that several of the other events also had different names
from the ones in the Cookbook, here’s a handy list of all the events supported by Audition and their names:

So that’s it, after three months a rather simple issue has been resolved. I hope it helped you as much as it would have helped me back when I was frantically searching the internet for this straightforward answer!

Ole Henrik Stabell

Ole Henrik Stabell

Hi, I'm Ole Henrik Stabell, feel free to call me Henry. I'm an Adobe extension developer from Stavanger, Norway. I also dabble in the fine art of photography on the side when i have the time.

Read More
Properly intercepting the Audition document save event
Share this