Solved

InDesign - Insert Date

Posted on 2006-04-07
6
5,532 Views
Last Modified: 2008-11-18
Ok... I feel really bad having to ask this question, but I cannot find an answer to it.

I am using Adobe InDesign CS2.

How do I get the current date in a text field?

I have a master page that needs to contain a text field showing the CURRENT date. I do not want to have to change this date every day, and certainly do not want to forget to change it and have the wrong day appear in the publication.

Thanks in advance!

-Jeremiah
0
Comment
Question by:WallaceR
  • 3
  • 2
6 Comments
 
LVL 16

Accepted Solution

by:
ddhamm earned 250 total points
ID: 16493623
This really isn't a dumb question at all.  What IS dumb is that InDesign doesn't have an automatic date feature built in.  You have to have a script to do it.

There is a scripts palette.  There is also a Scripting Guide on the software CD.  It is also posted here:
http://www.adobe.com/products/indesign/pdfs/indesign_cs_scripting_guide.pdf

1. What you would need to do is create a character style (called something like: autoDate) and apply that style to some text on a page.  
2. You need to save a script (i'll paste one below) with the extension .js in C:\Program Files\Adobe\Adobe InDesign CS2\Presets\Scripts
3. With that character style applied, double-click the script (using the scripts palette) with your document open and all instances of text assigned that style will be replaced with the current date

If you are on a MAC, I'll find out the specifics for that if you need them.

Below is a script that will make the date in this format ##/##/####

function LZ(n) {
 return (n > 9 ? n : '0' + n);
}

var d = new Date();
myDateString=(LZ(d.getMonth() + 1) + '/' +
LZ(d.getDate())+'/'+d.getFullYear());

app.findPreferences = null;
app.changePreferences = null;
myStyle = app.activeDocument.characterStyles.item("autoDate");
try {
 myStyle.name;
} catch (e) {
 // Style not defined in this doc so nothing to do
 exit();
}
app.activeDocument.search("",false,false,myDateString,{appliedCharacterStyle: myStyle})

I hope this helps!
DeeDee
0
 
LVL 16

Expert Comment

by:BongSoo
ID: 16561921
DeeDee,

Thats pretty impressive! Could you please provide the Mac (OSX) version?

BongSoo
0
 
LVL 16

Expert Comment

by:ddhamm
ID: 16564094
What I posted above might also work on a MAC, I just don't know enough about scripting and don't have a MAC to test it on.  But...

This is another thing I found is a script that is tied to an event (in this case, it adds a date when printing) and it would probably work on both a MAC and a PC.  This comes from someone using RougeSheep -- http://www.roguesheep.com/ineventpage/index.html.

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.


But, the thing about the other script I posted... it works in InDesign CS.  Maybe someone on a MAC can try it for me?

DeeDee
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:BongSoo
ID: 16700247
I will try at my earliest convenience, but I have a ton of stuff going on right now. Thanks though!

BongSoo
0
 

Author Comment

by:WallaceR
ID: 16700441
You rock ddhamm !!!
0
 
LVL 16

Expert Comment

by:ddhamm
ID: 16700475
Wow, thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question