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

Inspiring
June 12, 2006
If you don't want the comma, then:

return myParts[1] + " " + myParts[3];

should do the job.

Dave
Participating Frequently
June 12, 2006
Dave,

You're a miracle worker!

That did it. I wish I knew Javascript that way in the future if I wanted to create custom date formats, I could edit the last part of the script. I looked at the code and none of it makes sense like applescript.

I thought, what if I wanted to take the comma out and just have: june 2006 (date month)

return myParts[1] + "," + myParts[3];

I thought, all I have to do is remove the comma between the two parts and of course that didn't work. I guess I just have to rely on brilliant guys like yourself.

Thanks again for all your help. I'll check out the donations page.
Chad
Inspiring
June 12, 2006
Chad,

You have inspired me to add this script (and the variant you want) to my downloads area.

They're set up for use with InDesign CS2. If you need from for CS, you'll need to change the file extension names to ".js" instead of ".jsx".

I've gone off posting the text of scripts in the forum (except for small examples) because I've run into so many people who seem to be completely flumoxed by the installation instructions (particulary the part about plain text file). So, after you unzip the package, subject to the CS caveat above, the two scripts are ready to go. Just move or copy them to the Scripts folder.

I've added a copyright notice and included a link to my donations site to give people who wish to encourage my posting of scripts a vehicle for doing so. At some point soon, I'll update this package with a proper readMe that will include installation instructions and a caveat warning any users that they take any and all risks associated with using any of these scripts.

I also intend to add a catalog to the readMe to make it easier for people to find other scripts I've posted that could be of help.

The package is ready to download from:

http://pdsassoc.com/downloads/DateScripts.zip

Dave
Participating Frequently
June 12, 2006
Dave,

That was fast!

Since I don't know javascript and know only a fraction about applescript and scripting in InDesign, your second option sounds easier, but again... I am no programmer, more of a designer.

This is the result your script generated: Monday, June 12, 2006

So I would just need to elminate the Monday, 12?

Is that something simple to add? Could you float me a freebie add-on or just modify the java to produce the correct result?

Thanks again,
Chad
Inspiring
June 12, 2006
Chad,

Date is a JavaScript object type, so you could either tackle this by picking up just the information you want using the appropriate method, see:

http://www.devguru.com/technologies/javascript/10585.asp

or you could process the string my script creates to eliminate the characters you don't want.

Dave
Participating Frequently
June 12, 2006
Back to Dave's javascript (which works great by the way and is a clever solution to Adobe's lack of support for a special character for dates)

If I wanted my date to be formatted as only month, year...like "June, 2006" how would the last part of the script be modified?

Thanks
Chad
Participant
January 12, 2006
Olav,

I would appreciate it if you could send me the file.
I will also purchase the book, if you would provide the link to it.

Thanks,
herrmueller
Known Participant
January 12, 2006
Hi herrmueller--

The only place it's documented, as far as I know, is in my book "Real World Adobe InDesign CS" (or the CS2 version, which should be available any day now). I can send you an example file to play with, if you like (once I get back to the machine that has the file on it).

Thanks,

Ole
Participant
January 12, 2006
Hi

If you scroll up the page and find a heading: Messages then click show all you'll find the full descriptive message.

Peter
Participant
January 12, 2006
Olav,

Is there a resource or link that shows how to create this (.mrk) file?