# Run event listener only once after saving InDesign document?

I have a script _(that I did not write)_ that has a app.addEventListener('afterOpen', addVariables); event in it (addVariables being the name of the function). I altered it to be app.addEventListener('afterSave', addVariables); which works how I wanted it to except that it's creating a "never-ending" loop. Basically what's happening is that the script pulls the user's name (i.e.: Tia) and adds it as variable text onto the pasteboard in InDesign CC. With the "afterOpen" command, the name was updating anytime I opened the document; which defeated the purpose of the script since I want to know who last _saved_ the document, not who last opened the document _(which would always be me)_. The script works properly with the "afterSave" command in that it shows the name of the person who last saved it; however, I've now created the new problem that the script keeps looping* whenever anyone tries to save the document. **So, my question is this: can I tell the eventListener to run only once per document?** <br /> I am not familiar with javascript—I do have a fair understanding of applescript. _Thanks for any help!_ <br /><br /> - - - _iMac running osx 10.8.4 • Adobe InDesign CC • Using Adobe ExtendScipt Toolkit to edit_ - - - <br /> *It loops because once someone saves the document, the script runs and changes the text variable, which InDesign (correctly) notes as a change to the document. So now the document is flagged as "unsaved" (it has an asterisk next to the document name). If I hit command+s to save it again to "clear" the asterisk, then the eventListener picks up the afterSave command and updates the document again which in turn InDesign picks up as a change and flags it as unsaved... so you can see what I mean by it loops. You can tell the document to close (command+w) and tell it to save before closing, which it does, and then closes. However, I'd prefer to just save the document once, the variable text updates, and then if any further changes are made on that document _while it's still open_, the script will not run again. Obviously, I want the script to run once on each new document.

By:

Tutor
4.9 (14)

Experienced full stack software engineer fluent in Web technologies

## Still looking for help? Get the right answer, fast.

Get a free answer to a quick problem.
Most questions answered within 4 hours.

#### OR

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.