3 Replies Latest reply on Jun 18, 2015 8:32 AM by Loic.Aigon

    I keep getting an error from InDesign start up script

    carl.smith@rpmltd.com

      I have a couple of scripts that I need to add metadata (specifically CC username) into the Author field when starting a New document and Saving.

       

      The Save Doc script works great:

       

      #target indesign

      #targetengine "session"

       

      var

        myEventListener = app.eventListeners.item("mAfSave");

       

        if (!myEventListener.isValid) {

        myEventListener = app.addEventListener( "beforeSave", doJob );

        myEventListener.name = "mAfSave";

        }

       

      function doJob() {

        if (!app.documents.length) return;

        var myDoc = app.activeDocument;

        myDoc.metadataPreferences.author = app.userName; // Win or Mac app user

        myDoc.metadataPreferences.author = $.getenv("USER"); // MAC logged user

      //~ myDoc.metadataPreferences.author = $.getenv("USERNAME"); // Windows logged user

        }

       

      The New Doc script throws the following error (but if I click No it everything still seems to work):

      Screen Shot 2015-06-18 at 09.29.20.png

      #target indesign

      #targetengine "session"

       

      //Creates an event listener that will run after a new document is created.

      main();

      function main(){

      var myEventListener = app.eventListeners.add("afterNew", myAfterNewHandler);

      }

       

      function myAfterNewHandler(myEvent){

      var myDocument = myEvent.parent;

      myAddUserData(myDocument);

      function myAddUserData(myDocument){

      with(myDocument.metadataPreferences){

      author = app.userName; // Win or Mac app user

      author = $.getenv("USER"); // MAC logged user

      }

      }

      }

       

      Ideally, I would like both scripts in one, but I can live with 2 separate as it is at the moment.

       

      Thanks

      Carl