I got this! amazing! 🙂
When i change the indesign document name, would it be possible to get the variable to match and change as well?
it looks like it's always priting the first variable when i change the document name.
110538-001 Design sample design.ind
110538-002 Design sample design.ind
Hello @charlieg19576563
When you say: When i change the indesign document name, would it be possible to get the variable to match and change as well?
it looks like it's always priting the first variable when i change the document name.
110538-001 Design sample design.ind
110538-002 Design sample design.ind
I assume you're changing the file name by doing a Save As, if so give the below code a try as it will update the text variable "Doc Name 10" contents with the new document name.
#targetengine "session"
var eventListener = app.addEventListener("afterOpen", myCustomTextVariable, false);
function myCustomTextVariable() {
try {var doc = app.documents[0];
var fileName = doc.name.replace(/.indd$/i, "");
if(fileName.length >= 10){
var tenName = fileName.slice(0,10);
}else{
exit();
}
var tv = doc.textVariables.add({ variableType: VariableTypes.CUSTOM_TEXT_TYPE,
name: "Doc Name 10"
});
tv.variableOptions.contents = tenName;
} catch(err) {}
}
var eventListener = app.addEventListener('afterSaveAs', myCustomTextVariableUpdate, false);
function myCustomTextVariableUpdate() {
try {var doc = app.documents[0];
var fileName = doc.name.replace(/.indd$/i, "");
if(fileName.length >= 10){
var tenName = fileName.slice(0,10);
}else{
exit();
}
app.activeDocument.textVariables.item('Doc Name 10').variableOptions.contents = tenName;
} catch(err) {}
}
Regards,
Mike