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);
}
}
}
}