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

Filename of script usable in startup-script?

Advocate ,
Oct 12, 2018 Oct 12, 2018

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

563

Translate

Translate

Report

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

correct answers 1 Correct answer

Guide , Oct 12, 2018 Oct 12, 2018

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

Votes

Translate

Translate
Guide ,
Oct 12, 2018 Oct 12, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Guru ,
Oct 13, 2018 Oct 13, 2018

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Advocate ,
Oct 15, 2018 Oct 15, 2018

Copy link to clipboard

Copied

Purrrrfect – thanks you guys!

tumblr_m1viylSKgh1qbxi45o2_500.gif

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

Votes

Translate

Translate

Report

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
Guru ,
Oct 15, 2018 Oct 15, 2018

Copy link to clipboard

Copied

Not sure you are looking for this but  to get the username you can use $.getenv($.os[0]==='M' ? 'USER' : 'username');

Votes

Translate

Translate

Report

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
Guide ,
Oct 15, 2018 Oct 15, 2018

Copy link to clipboard

Copied

LATEST

Trevor, I mixed that up with app.activeScript occasionally not working.

Haven't done any serious scripting in a while.

Votes

Translate

Translate

Report

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