Reply To: Script to import partial filename

#92526
Omar Khatib
Member

One more issue I can’t figure out. I added an if statement to account for document that don’t have the “SlugArea” text variable. the new script looks like this:

#target indesign;
#targetengine “mysession”;

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

app.eventListeners.add(“beforeSave”, myHandler);
app.eventListeners.add(“beforeSaveAs”, myHandler);

When this runs the first time on a fresh new template I get an error message…

null is not an object
Do you want to disable this event handler?
Check Box Don’t Show Again No Yes

When you choose “No” this script continues and works but it makes me feel like something bad is happening that I am not aware of.

What could be causing this error? Is it hurting anything? Is there a way to make it go away without checking that box?

This article was last modified on March 1, 2017

Comments (0)

Loading comments...