var myDocument = app.activeDocument; // document
activeDocument.rulerOrigin = [0, activeDocument.height];
var format_preset = "{FILENAME} {DATE} {TIME}"; // выводимая информация
// var format_preset = "{FILENAME}{FILEEXT} {DATE} {TIME}"; // выводимая информация
var Dateformat = "dd.mm.yyyy"; // формат даты
// Text =============================================================================
var myTextFrame = myDocument.textFrames.add();
myTextFrame.contents = " ";
myTextFrame.top = -20;
myTextFrame.left = 20;
myTextFrame.selected = true;
redraw();
date_n_time();
function TodayDate()
{
var Today = new Date();
var Day = Today.getDate();
var Month = Today.getMonth() + 1;
var Year = Today.getYear();
var Year = Today.getFullYear();
var PreMon = ((Month < 10) ? "0" : "");
var PreDay = ((Day < 10) ? "0" : "");
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 = ""; // текст после времени
var PreHour = ((Hours < 10) ? "0" : "");
var PreMin = ((Minutes < 10) ? "0" : "");
return PreHour + Hours + ":" + PreMin + Minutes + Suffix;
};
function DateUpdate(name)
{
var docpath = myDocument.path.fsName;
var docname = myDocument.name.replace(/(.*?)(?:\.([^.]+))?$/, '$1');
var extension = myDocument.name.replace(/(.*?)(?:(\.[^.]+))?$/, '$2');
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(/\{FILEEXT\}/, extension);
var content = content.replace(/\{DATE\}/, TodayDate());
var content = content.replace(/\{TIME\}/, TodayTime());
return content;
};
function date_n_time()
{
selection[0].name = "actualDate:" + format_preset;
selection[0].contents = DateUpdate(selection[0].name);
selection[0].selected = false;
};