Reply To: Script to import partial filename

#112601
Scott Rudy
Participant

I have a start on a different way but do not know how to get it to actually work….

the below script will insert the beginning of the filename up to that underscore into the document at the point where you have the text insertion point.

#target indesign;
#targetengine “myCustomGetFileNameHandler”;

fileNameVariable = app.activeDocument.name.split(“_”)[0]; // get XXXXX from XXXXX_Name1_Name2_Name3.indd file name
// app.activeDocument.textVariables.item (“myVariable”).variableOptions.contents = fileNameVariable;

myTextFrame = app.selection[0];
firstInsertionPoint = myTextFrame.insertionPoints[-1].index;
myTextFrame.contents += fileNameVariable;
myAddedText =
myTextFrame.characters.itemByRange(myTextFrame.insertionPoints[firstInsertionPoint],
myTextFrame.insertionPoints[-1]);

what i’m thinking is can i replace the insertion point with a grep find/change that will search the entire document for \<[\u]+[\d+]_
which will find my file name format that is ABC123456 (sometimes i have a few extra letters at the beginning)
and replace it with the “file name variable”

ideally i would like it to call up an alert if they are different in case there was a reason for the difference

scott

This article was last modified on December 7, 2018

Comments (0)

Loading comments...