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
Use $.fileName - you must launch the script from InDesign though, it does not work from ESTK targeting InDesign.
Copy link to clipboard
Copied
Use $.fileName - you must launch the script from InDesign though, it does not work from ESTK targeting InDesign.
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.
Copy link to clipboard
Copied
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
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');
Copy link to clipboard
Copied
Trevor, I mixed that up with app.activeScript occasionally not working.
Haven't done any serious scripting in a while.