Skip to main content
Known Participant
September 30, 2020
Answered

Add operator name to a text variable is a slug

  • September 30, 2020
  • 2 replies
  • 872 views

Hello.

We have multiple operators and would like to add the name of the last operator for a document to a slug.

Currently we use text Variables to dynamically update filename and last modified date etc but i cannot see one for user.

It would be the name of the operator who last worked on it, so whomever is logged in.

InDesign 2020 on OSX.

Many thanks.

This topic has been closed for replies.
Correct answer Mike Bro

Hello wobblewoo!

it's a .jsx script not an Apple script. Copy the code into the text edit app and change the format to "Make Plain Text" and save it as a .jsx file.

 

Regards,

Mike

2 replies

wobblewooAuthor
Known Participant
October 1, 2020

Hello Mike, thanks for your help so far.

I've entered the username (File > User) into ID, no problems there.

When i cut and paste your code into Script Editor and saved as 'setUserScript.scpt' then placed here:

/Applications/Adobe InDesign 2020/Scripts/startup scripts/setUserScript.scpt

When i quit and then restart ID i get this error:

If i then try and compile the script from within Script Editor i get this:

Im on OS 10.15.7 and ID 15.0.1 if that matters.

Wx

Mike BroCorrect answer
Brainiac
October 1, 2020

Hello wobblewoo!

it's a .jsx script not an Apple script. Copy the code into the text edit app and change the format to "Make Plain Text" and save it as a .jsx file.

 

Regards,

Mike

wobblewooAuthor
Known Participant
October 1, 2020

Perfect. Thanking you.

Brainiac
September 30, 2020

Hello wobblewoo!

This shold work for what your after......

 

1. Start off by creating a new text Variable;

Name: User

Type: Custom Text

Text: leave blank

2. Apply the "User" text Variable to the text frame for the slug.

3. On every users machine you'll need to install the Indesign Startup Script below.

  • ‎⁨Startup location: Mac⁩ ▸ ⁨Applications⁩ ▸ ⁨Adobe InDesign 2020⁩ ▸ ⁨Scripts⁩ ▸ ⁨startup scripts⁩

 

 

#targetengine "session"

var eventListener = app.addEventListener("beforeSave", rememberLastUser, false);     

function rememberLastUser(event) {
	try {var doc = event.parent;
        app.activeDocument.textVariables.item('User').variableOptions.contents = app.userName;} catch(err) {}
}

 

Each time the document is saved by a different user, the Text: in the "User" text Variable will be updated.

Regards,

Mike

 

 

wobblewooAuthor
Known Participant
October 1, 2020

Thanks ever so Mike, however when compiling i get an error.

 

It's hilighting the eventListener on the second line of code and says:

Expected end of line, etc. but found identifier.

 

Can you help?

Brainiac
October 1, 2020

Hello wobblewoo!

 

Where are you trying to run the script from? It's a Startup Script and needs to be ran from the location below:

  • ‎⁨Startup Script location: Mac⁩ ▸ ⁨Applications⁩ ▸ ⁨Adobe InDesign 2020⁩ ▸ ⁨Scripts⁩ ▸ ⁨startup scripts⁩

 

Also I forgot to mention each user needs to set their user name in InDesign, Go to the File menu ▸ user  and enter User Name.

Regards,

Mike