Reply To: Script to import partial filename

#92569
Omar Khatib
Member

I tried the script as is and it didn’t work. Openning InDesign got:
Error Number: 90884
Error String: No documents are open

The variable did not change as expected.

In our workflow the template we are using for this project will always have the “SlugArea” variable. We want the script to simply ignore any other document.

I was able to take parts of the new script and got something working, it looks like this:

#target indesign;
#targetengine “mysession”;

var myHandler = function(ev)
{
try{
if(app.eventListeners.length > 2){
app.removeEventListener(“afterSave”, myHandler);
app.removeEventListener(“afterSaveAs”, myHandler);
}
}catch(e){
$.writeln(e);
}

if(app.activeDocument.textVariables.item(“SlugArea”).isValid){
fileNameVariable = app.activeDocument.name.match(/[A-Z]{2,10}(?=)/)[0];
// alert(fileNameVariable);
app.activeDocument.textVariables.item(“SlugArea”).variableOptions.contents = fileNameVariable;
}
else{
//…
};
}

app.eventListeners.add(“afterSave”, myHandler);
app.eventListeners.add(“afterSaveAs”, myHandler);

I am going to keep testing but it seems to be working.

On line 7 “if(app.eventListeners.length > 2){“:

In your script you had it set as “> 0”. When that was the case the script only worked on the first page that was opened, so I changed to “> 2” and it works continuously.

Thanks again Oleh! Do you have a donation page or something?

This article was last modified on March 2, 2017

Comments (0)

Loading comments...