Skip to main content
Participant
March 11, 2010
Answered

Retrieve/Place current date-time into text box

  • March 11, 2010
  • 2 replies
  • 6835 views

Hello, I'm wondering if anyone has experimented with dynamically retrieving the computer's current date/time and placing that information into a text box? It seems like a simple enough action, but i can't find any documentation related to this topic. I suspect this method of call and retrieve behavior could be unexpectedly useful in a lot of situations, for a lot of people!

-joel

This topic has been closed for replies.
Correct answer brettpolo

You don't need a script to do this.  Under the Type menu, there is a 'Text Variables...' submenu.  This will let you define text variables, and place them into text boxes.  There is a preset variable called 'Output Date', which will display the current date (MM/dd/yy) when a PDF is output.  If you want to display the time as well, under 'Text Variables...', go to 'Define...', and you can define your own.  Under 'Type', select output date, and add any variable data you want.  The format for time and date should look something like this:

hh:mm:ss MM/dd/yy

I've found that Text Variables don't update in the display very consistantly, but I just tested this, and regardless of the displayed value, the output PDF has the correct time and date.

If you want to control text variables with javaScript, check out the TextVariable(s) and TextVariableInstance(s) classes.

As a side note, text variables work fine if you want date/time, page, etc, but I really wish they would add a bit more functionality, especialy with things like seperation name, color profile, and PDF output profile.  It would be a huge timesaver to have all of this type of metadata be easily inserted.

2 replies

brettpoloCorrect answer
Inspiring
March 12, 2010

You don't need a script to do this.  Under the Type menu, there is a 'Text Variables...' submenu.  This will let you define text variables, and place them into text boxes.  There is a preset variable called 'Output Date', which will display the current date (MM/dd/yy) when a PDF is output.  If you want to display the time as well, under 'Text Variables...', go to 'Define...', and you can define your own.  Under 'Type', select output date, and add any variable data you want.  The format for time and date should look something like this:

hh:mm:ss MM/dd/yy

I've found that Text Variables don't update in the display very consistantly, but I just tested this, and regardless of the displayed value, the output PDF has the correct time and date.

If you want to control text variables with javaScript, check out the TextVariable(s) and TextVariableInstance(s) classes.

As a side note, text variables work fine if you want date/time, page, etc, but I really wish they would add a bit more functionality, especialy with things like seperation name, color profile, and PDF output profile.  It would be a huge timesaver to have all of this type of metadata be easily inserted.

Jongware
Community Expert
Community Expert
March 12, 2010

Now why didn't I think of that ...

Top entry is the Date Class. Bottom entry controls variables. I must have developed a blind spot when I read "script" ...

Jongware
Community Expert
Community Expert
March 11, 2010

It depends on what you mean -- exactly. Do you "need" an InDesign document that continuously holds the current date and time? What if you print it? Export to PDF? Send it off to be printed, cut, bound, and sold as a book?

It's extremely easy (really) to get hold of the current date & time at the moment you run a script, and put that into some text frame. "Date" is a base class of Javascript and has everything you'd probably want for that.

On the other hand, if you want ID to automatically and continuously update date and time in some document, you would need a script that continuously keeps running in the background. What a waste of resources that would be -- doesn't your OS have a clock applet you could look to instead?

Participant
March 11, 2010

Yes, thank you, sincerely, your knowledge of the possibilities has helped me define more precicely what it is i am looking for. The ideal scenario is that the javascript base class Date is activated upon PDF export -- placing the current date into the designated text frames. I do not yet know how to implement this, but this was already helpful as i said, so thanks again.

If anyone would like to share how to enact this script, i, and anyone else reading would be quite privelaged.

-joel

Steven__
Inspiring
March 11, 2010

Maybe you can make a menuAction event listener for pdf menu which will update your value.