Skip to main content
Legend
October 12, 2018
Answered

Filename of script usable in startup-script?

  • October 12, 2018
  • 1 reply
  • 802 views

Hey guys,

i have this neat startup-script, and i'm wondering if it would be possible to use its filename as content of a variable?

#targetengine "session"

main();

function main()

{

var myEventListener1 = app.addEventListener("beforeSave",  setMetadata, false);

var myEventListener2 = app.addEventListener("afterSaveAs",  setMetadata, false);

var myEventListener4 = app.addEventListener("beforeExport", setMetadata, false);

  var myEventListener5 = app.addEventListener("afterPrint", setCopys, false);

}

    

     function setMetadata()

    {

     app.activeDocument.metadataPreferences.author = "XXX";

      app.activeDocument.metadataPreferences.documentTitle = app.activeDocument.name;

    }

As you see, I need to edit the author ('XXX') for every workspace the script is rolled out to.

My idea is to use the filename for that. This way I could prepare the scripts' filename and dont need to touch the content.

Is it possible to use fn for this, exspecially start-up scripts?

metadata_AuthorName.AuthorSurName.jsx

This topic has been closed for replies.
Correct answer Dirk Becker

Use $.fileName - you must launch the script from InDesign though, it does not work from ESTK targeting InDesign.

1 reply

Dirk BeckerCorrect answer
Legend
October 12, 2018

Use $.fileName - you must launch the script from InDesign though, it does not work from ESTK targeting InDesign.

Trevor:
Legend
October 14, 2018

I think $.fileName will work from ESTK targeting InDesign as long as the script is saved.

If it's not saved then it won't work as there's no file path.

DBLjanAuthor
Legend
October 15, 2018

Purrrrfect – thanks you guys!

I squished the filename down with this…

var username = $.fileName.replace(/^.*(\\|\/|\:)/, '').slice(14).replace(/\.[^.$]+$/, '').split(".");

app.activeDocument.metadataPreferences.author = username[0]+" "+username[1];

to get the user from the fn:
AutoMetaDaten_John.Doe.jsx