write date and time INDESIGN CS

Hello fellow scripter !
I have a script in Java, to write date and time on indesign spread, however the rpoblem with this script is that you have to manually always run it before you print page, and sometimes we just forget … so here is where I need help:
How can you make Indesign select all boxes with (white arrow) in only layer called: date and time
After this selection happend launch new script seen below
then finish with printing page.

This way I can just click on one script that will select text box on layer : date and time, - update the info and print page, all at once…

If someone can help me with that I would be very greatfull

R

Here is JS script to write date and time :

// -------------------------------------------------------------------

var language=“en”; // “de” fuer Deutsch

// -------------------------------------------------------------------

var WR=“WR-DateAndTime_ID v0.8nn”;

if (language == “de”) {

var format_preset = “{FILENAME} ({DATE} - {TIME})”;

var MSG_askformat = WR+“Soll das Textobjekt als Datum/Uhrzeit formatiert werden? Formate:n{DATE}, {TIME}, {FILE}, {FILEPATH} und {FILENAME}:”
var MSG_editformat = WR+“Datums-/Uhrzeitformat bearbeiten (Leer = entfernen). Formate:n{DATE}, {TIME}, {FILE}, {FILEPATH} und {FILENAME}:”
var MSG_notexto = WR+“Kein Textrahmen. Ein Textrahmen muss mit dem Auswahl-Werkzeug (nicht Textwerkzeug) ausgewxE4hlt werden.”;
var MSG_selectedmany = “Zum Markieren als aktuelles Datum/Uhrzeit darf nur ein Textrahmen ausgewxE4hlt sein und falls Sie die Daten aktualisieren wollen, darf kein Objekt ausgewxE4hlt sein.”;
var MSG_nodocs = WR+“Kein Dokument gexF6ffnet.”
var Timeformat = 24;
var TimeSep = “:”;
var AM = " am";
var PM = " pm";
var Dateformat = “dd.mm.yyyy”;

} else {

var format_preset = “{FILENAME} ({DATE}, {TIME})”;

var MSG_askformat = WR+“Do you want to mark the textobject as actual date’n’time? Formats:n{DATE}, {TIME}, {FILE}, {FILEPATH} und {FILENAME}:”
var MSG_editformat = WR+“Edit date’n’time (empty = remove). Formats:n{DATE}, {TIME}, {FILE}, {FILEPATH} und {FILENAME}:”
var MSG_notexto = WR+“No textframe. A textframe has to be selected with the selection-tool (not the text-tool)!”;
var MSG_selectedmany = “To mark as actual date’n’time, you have to select only one textframe. If you want to update the date’n’time-objects, there must be no object selected.”;
var MSG_nodocs = WR+“You have no open document.”
var Timeformat = 12;
var TimeSep = “:”;
var AM = " am";
var PM = " pm";
var Dateformat = “mm/dd/yyyy”;

}

var error=0;

if (app.documents.length<1) {
error++;
alert(MSG_nodocs)
}

if (error < 1) {
date_n_time();
}

function TodayDate()
{
var Today = new Date();
var Day = Today.getDate();
var Month = Today.getMonth() + 1;
var Year = Today.getYear();
var PreMon = ((Month < 10) ? “0” : “”);
var PreDay = ((Day < 10) ? “0” : “”);
if(Year < 999) Year += 1900;

var theDate = Dateformat.replace(/dd/,PreDay+Day);
theDate = theDate.replace(/mm/,PreMon+Month);
theDate = theDate.replace(/d/,Day);
theDate = theDate.replace(/m/,Month);
theDate = theDate.replace(/yyyy/,Year);
theDate = theDate.replace(/yy/,Year.toString().substr(2,2));

return theDate;

}

function TodayTime()
{
var Today = new Date();
var Hours = Today.getHours();
var Minutes = Today.getMinutes();
var Suffix = “”;
if (Timeformat == 12) {
if (Hours >= 12 ) {
Suffix = PM;
} else {
Suffix = AM;
}
if (Hours >= 13) {
Hours = Hours - 12;
}
if (Hours < 1) {
Hours = Hours + 12;
}
}
var PreHour = ((Hours < 10) ? “0” : “”);
var PreMin = ((Minutes < 10) ? “0” : “”);
return PreHour+Hours+TimeSep+PreMin+Minutes+Suffix;
}

function DateUpdate(Name) {
try {
var docpath = app.activeDocument.filePath.fsName;
} catch (e) {
docpath=“”;
}
var docname = app.activeDocument.name;
if (docpath.slice(2,3) == "") {
docsep = "";
} else {
docsep = “:”;
}
var content = Name.slice(11);
var content = content.replace(/{FILE}/,docpath+docsep+docname);
var content = content.replace(/{FILEPATH}/,docpath);
var content = content.replace(/{FILENAME}/,docname);
var content = content.replace(/{DATE}/,TodayDate());
var content = content.replace(/{TIME}/,TodayTime());
return content;
}

function date_n_time()
{
if (app.selection.length == 1) {
if (app.selection[0].toString() == “[object TextFrame]”) {
if (app.selection[0].label.slice(0,11) == “actualDate:”) {
dateformat = app.selection[0].label.slice(11);
dateformat = prompt(MSG_editformat, dateformat);
if(dateformat == “” ) {
app.selection[0].label=“”;
//app.selection.select(false);
}
if(dateformat && dateformat !=“” ) {
app.selection[0].label=“actualDate:”+dateformat;
app.selection[0].contents = DateUpdate(app.selection[0].label);
}
} else {
dateformat = app.selection[0].contents;
if(dateformat.search(/{DATE}/) == -1 && dateformat.search(/{TIME}/) == -1 && dateformat.search(/{FILE[A-Z]*}/) == -1) dateformat = format_preset;
dateformat = prompt(MSG_askformat, dateformat);
if (dateformat) {
app.selection[0].label=“actualDate:”+dateformat;
app.selection[0].contents = DateUpdate(app.selection[0].label);
//app.selection[0].select(false);
}
}
} else {
alert ( MSG_notexto );
}
} else if (app.selection.length > 1) {
alert ( MSG_selectedmany );
} else {
var textFrames = app.activeDocument.textFrames;
for (var i = 0 ; i < textFrames.length; i++)
{
if (textFrames[i].label.slice(0,11) == “actualDate:”) {
textFrames[i].select(true);
textFrames[i].contents = DateUpdate(textFrames[i].label);
}
}

}
}

That text frame on special layer : Date and time is already created on template, so script does not have to do that, just needs to select that text frame + run new script shown above… I think this is something simple but I cant figure out how to do it… please help

R

Since the JavaScript uses Script Label; Use that and forget the layers:

Kari

Kari Thanks,

It is selecting correct box but I am getting this error:

Indesign Cs got an error: alias" Macintosh HD:Applications:Adobe…" doesn’t understand the do script message. - 1708

still cant figure out how to run that other Java script , do you know why??

In this line:

do script alias “OSX:Applications:Adobe InDesign CS:Presets:Scripts:Date-Time:WR-DateAndTime_ID.js” language javascript

you have to write your exact path/filename.

Here is BigCat (http://ranchero.com/software/bigcat/) contextual menu script that helps you find it:

Or use this simple Finder script:

Kari

Thanks for sucha quick respond!
that next script to find location of file is awesome!!! another great tool…

however my location was good, and error still is there it seems like Indesign does not know what to do with command " do script"

it would be so great if it does work… just one more step…

It’ll auto launch a script on print events.

http://www.macupdate.com/info.php/id/16237

I don’t know what is wrong, The script works fine here!

(You have InDesign CS Version 3.0.1?)

Kari

digest4d:
Thanks for the link, it is a great plug in, that would be awesome to have but it is juts demo version and full version is pretty costly…

Kari:

Yes thats exactly what I have , same version , but still gives me same error, since it works on your comp, that gives me more hope to try out other stuff, maybe moving that script to a different location or something… I will experience …

Thanks

Maybe I should try to write this script in apple script, that would save whole bunch of problems…or is there some sort of converter from Java to apple script??

There is no converter.

The script that I posted works fine with other peoples machines, so either you are doing something wrong or there is something wrong with your Mac.

Kari

after few adjustments, I got it to work, not sure why it was not working before, but it works now and thats great!!!

Just one more step to add … is there a way add command at the end of script to open print window??

Thanks

R

Just add: print

Kari

tell document 1

  • of course !!!
    Thanks a lot, everything works great!!!