Skip to main content
LynxKx
Inspiring
January 3, 2022
Answered

Script to edit Custom text variable

  • January 3, 2022
  • 3 replies
  • 1226 views

I just need a simple script that will change the contents of my custom text variable.

I have a copyright date set as a variable, this variable adjusts the date in mutliple places, I'm just trying to find script language to add to my new year updates script so I dont have to go into the vairable each time I'm updating a old document.

this is what Ive been playing with but clearly isnt working

var doc = app.activeDocument;
var copyD = doc.textVariables.item ('Copyright date').variableOptions;

if (copyD.content == "2021") { copyD.content = "2022"; }

 

This topic has been closed for replies.
Correct answer brian_p_dts
app.activeDocument.textVariables.item ('Copyright date').variableOptions.contents = new Date().getFullYear().toString();

 

3 replies

Marc Autret
Legend
January 6, 2022

Hi @LynxKx 

See also the script InstantVariable for easily editing any custom variable by just selecting an instance in the document:

https://www.indiscripts.com/post/2019/08/instantvariable-edit-quickly-your-indesign-variables

 

Best,

Marc

LynxKx
LynxKxAuthor
Inspiring
January 6, 2022

I did come across that ... I use shortcuts usually to access my variables quickly - but its a good thing to have in my back pocket if the need arises 🙂

jctremblay
Community Expert
Community Expert
January 3, 2022

There a script already available that allow editing of any custom text variable.

 

https://creativepro.com/files/kahrel/indesign/variables.html

LynxKx
LynxKxAuthor
Inspiring
January 4, 2022

I actually did come across this when I was researching but couldnt use it to do what I needed and I knew there was a simpler solution, Thanks for replying to the string though! Appreciate this community a ton while I'm teaching myself java .... if you know of any good resources that will help me learn faster - that would be awesome!

brian_p_dts
Community Expert
Community Expert
January 4, 2022

If you're not aware, the online searchable DOM is here: 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

 

A vital resource for scripters. 

 

 

 

brian_p_dts
Community Expert
brian_p_dtsCommunity ExpertCorrect answer
Community Expert
January 3, 2022
app.activeDocument.textVariables.item ('Copyright date').variableOptions.contents = new Date().getFullYear().toString();

 

LynxKx
LynxKxAuthor
Inspiring
January 3, 2022

Thank you! I've been searching through so much code and everything I could find was so much more complicated!