Solved

InDesign - Insert Date

Posted on 2006-04-07
6
5,333 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
Comment Utility
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
Comment Utility
DeeDee,

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

BongSoo
0
 
LVL 16

Expert Comment

by:ddhamm
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Expert Comment

by:BongSoo
Comment Utility
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
Comment Utility
You rock ddhamm !!!
0
 
LVL 16

Expert Comment

by:ddhamm
Comment Utility
Wow, thanks!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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.
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
In this second Micro Tutorial in the series,  viewers will learn more basic shortcuts and functions of Illustrator. In this tutorial you will learn about the eyedropper tool, zoom , ellipses and more.

772 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

12 Experts available now in Live!

Get 1:1 Help Now