Skip to main content
Participant
January 12, 2006
Answered

Insert auto date

  • January 12, 2006
  • 23 replies
  • 6599 views
Hi

First, sorry if you've also read the InDesign Forum, I've cross posted this enquiry there as well.

I need to insert a date/time when the IDCS2 document is printed, i've looked on the web and various other resources like this Forum.

Peter

Set to not expire because of active cross references elsewhere
This topic has been closed for replies.
Correct answer _Dave_Saunders_
Inserting and later updating a date is easy.

Triggering it to a specific event is less easy. RogueSheep has a product that allows you to tie a script to an event. So, if you wrote a script to replace all instances of a character style named (say) CurrentDate with the current date and tied this to happen before a Print command was actually executed. That would do it.

A JavaScript to do this would look something like this:
//DESCRIPTION: Update Date in Active Document


/*
Updates all instances of current date in a document to reflect the
actual date when the script is run. Depends on character style named
"CurrentDate" -- does nothing if document lacks said style.
*/

if (app.documents.length == 0) { exit() }
myDoc = app.activeDocument; //Global
var myStyle = myDoc.characterStyles.item("CurrentDate");
if (myStyle == null) { exit () }

// If we get here, we have work to do
var myDate = getDateString();

// Use Find/Change across document to update date:
app.findPreferences = app.changePreferences = null;
myDoc.search("", false, false, myDate, {appliedCharacterStyle:myStyle});

function getDateString() {
var today = new Date();
var myDateString = today.toLocaleDateString();
myParts = myDateString.split(" 0");
if (myParts.length != 1) {
myDateString = myParts[0] + " " + myParts[1];
}
return myDateString.slice(0,-5) + "," + myDateString.slice(-5);
}
To use the script, copy and paste to a text editor and save as a plain text file with an appropriate name in the form UpdateDate.jsx in the Scripts folder of the Presets folder of your InDesign CS2 folder (you could put it in a subfolder if you wish). Then to run the script, double-click its name in the Scripts palette.

If you want to work it with RogueSheep's InEventScript, follow their directions on how to connect this to the Print command. If you want the date in a different format, change the function to provide the format -- this might require some research.

Dave

23 replies

Known Participant
January 12, 2006
Hi Peter--

While Dave's suggestion is great, why not turn on the Page Information option in the Marks and Bleed section of the Print dialog box? That will print the date below the bottom of page. If your page is the same size as the paper you're printing on, you can modify the location of the page information by creating a custom printer marks definition file (.mrk).

Thanks,

Ole
Participant
January 12, 2006
Dave you're a star - no a big star - many thanks it works just fine.

This has given me a head start on the date and gives food for thought about other things that can be done by automation.

Cheers

Peter
_Dave_Saunders_Correct answer
Inspiring
January 12, 2006
Inserting and later updating a date is easy.

Triggering it to a specific event is less easy. RogueSheep has a product that allows you to tie a script to an event. So, if you wrote a script to replace all instances of a character style named (say) CurrentDate with the current date and tied this to happen before a Print command was actually executed. That would do it.

A JavaScript to do this would look something like this:
//DESCRIPTION: Update Date in Active Document


/*
Updates all instances of current date in a document to reflect the
actual date when the script is run. Depends on character style named
"CurrentDate" -- does nothing if document lacks said style.
*/

if (app.documents.length == 0) { exit() }
myDoc = app.activeDocument; //Global
var myStyle = myDoc.characterStyles.item("CurrentDate");
if (myStyle == null) { exit () }

// If we get here, we have work to do
var myDate = getDateString();

// Use Find/Change across document to update date:
app.findPreferences = app.changePreferences = null;
myDoc.search("", false, false, myDate, {appliedCharacterStyle:myStyle});

function getDateString() {
var today = new Date();
var myDateString = today.toLocaleDateString();
myParts = myDateString.split(" 0");
if (myParts.length != 1) {
myDateString = myParts[0] + " " + myParts[1];
}
return myDateString.slice(0,-5) + "," + myDateString.slice(-5);
}
To use the script, copy and paste to a text editor and save as a plain text file with an appropriate name in the form UpdateDate.jsx in the Scripts folder of the Presets folder of your InDesign CS2 folder (you could put it in a subfolder if you wish). Then to run the script, double-click its name in the Scripts palette.

If you want to work it with RogueSheep's InEventScript, follow their directions on how to connect this to the Print command. If you want the date in a different format, change the function to provide the format -- this might require some research.

Dave