?
Solved

InDesign - Insert Date

Posted on 2006-04-07
6
Medium Priority
?
5,727 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 16

Accepted Solution

by:
ddhamm earned 1000 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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Suggested Courses

762 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