Solved

InDesign - Insert Date

Posted on 2006-04-07
6
5,441 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
In this Micro Tutorial viewers will learn the basic shortcuts and functions in InDesign.
In this Micro Tutorial viewers will learn how to remove an unwanted object using Photoshop’s feature known as content-aware fill.

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now