Reply To: Script to import partial filename

#71696
Oleh Melnyk
Member

I don’t understand what you want to do exactly, but try this:

1) go to Type > Text Variables > Define
2) create new varialbe, and give it name “myVariable”, and type – “Custom Text”
3) paste this variable to your document
4) create .jsx file, and copy/past there this code:

#target indesign;
#targetengine "myCustomGetFileNameHandler";

myHandler = function(ev)
{
    fileNameVariable = app.activeDocument.name.split("_")[0]; // get XXXXX from XXXXX_Name1_Name2_Name3.indd file name
    alert(fileNameVariable); // show XXXXX
    app.activeDocument.textVariables.item ("myVariable").variableOptions.contents = fileNameVariable;
    // ...do what you need here...
}

app.activeDocument.addEventListener("beforeSave", myHandler);

5) save this .jsx script file, and run it before saving your document – it should get XXXXX part from document name and set it as your text variable value
6) if you want this script to load automatically – you can put it to “startup scripts” folder

This article was last modified on November 18, 2014

Comments (0)

Loading comments...