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

Is it possible to run a script automatically when a document is saved?

New Here ,
Jun 11, 2015 Jun 11, 2015

What I am after is a script (for mac) that will enter the user name in the Author field of the File Information.

If the script could dynamically pick up the user name, that would be useful, but not essential. The main thing is it would need to run on save as I cannot rely on people to remember to enter the details themselves.

Any help hugely appreciated

Carl

TOPICS
Scripting
474
Translate
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
Mentor ,
Jun 11, 2015 Jun 11, 2015

Hi,

If you place a script into user "Startup Scripts" folder

and

if your script will define an eventListener (type "afterSave")

==> it could be done.

Example:

#target indesign

#targetengine "session"

var

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

  if (!myEventListener.isValid) {

  myEventListener = app.addEventListener( "afterSave", 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("USERNAME"); // Windows logged user

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

  }

Jarek

Translate
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
New Here ,
Jun 11, 2015 Jun 11, 2015

Thanks,

That seems to kind of work... But now my ⌘S command is not working and when I manually save the file (using the File Menu) the Title bar of the doc doesn't recognise the save Screen Shot 2015-06-16 at 10.29.49.png and still gives the "Save Changes" dialogue box when you close.

Also, just realised it really messes around when adding files to a Book!

Any ideas? I don't really know about coding so I really appreciate the help.

Carl

Translate
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
Mentor ,
Jun 16, 2015 Jun 16, 2015

Hi,

1. No idea what you mean by "⌘S command is not working".

2. If your goal is to edit file (modify file info) after save ==> file has some changes (unsaved) right?

3. Maybe changing eventListener type to "beforeSave" could help?

Jarek

Translate
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
New Here ,
Jun 16, 2015 Jun 16, 2015
LATEST

NAILED IT!

Thanks Jarek!

Carl

Translate
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