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