Поехали.
Календарик на любой месяц
#target photoshop
function Calendar() {
var n = new Date();
// script version
this.Version = "3.0";
// initial values of the font
this.params = new Object();
this.paramsFile = new File(app.preferencesFolder + "/script_params_calendar.txt");
this.LoadParams = function() {
var z = true;
if (this.paramsFile.open("r")) {
while (!this.paramsFile.eof) {
var c = "", p = "", v = "";
while (c != "=" && !this.paramsFile.eof) {
c = this.paramsFile.read(1);
if (c != "=") p += c;
}
while (c != "\n" && !this.paramsFile.eof) {
c = this.paramsFile.read(1);
if (c != "\n") v += c;
}
if (p == "Version") {
if (v != this.Version || v == "undefined") {
this.paramsFile.close();
this.paramsFile.remove();
z = false;
break;
}
} else {
if (v == "null") v = null;
else if (v == "true") v = true;
else if (v == "false") v = false;
this.params[p] = v;
}
}
this.paramsFile.close();
} else z = false;
return z;
}
if (!this.paramsFile.exists || !this.LoadParams()) {
this.params = { // as to default
FontName: "TimesNewRomanPSMT",
FontSize: 50,
AntiAlias: "AntiAlias.CRISP",
Color0: "000000",
Color1: "FF0000",
VerticalDirection: true,
IncreaseIndent: 1.5
}
}
// all strings which are used in GUI and the document
switch (app.locale.substr(0, 2)) {
case "ru":
this.str = {
Title: "Календарь",
Date: "Дата",
Month: "Месяц(&M)",
Year: "Год(&Y)",
Parameters: "Параметры",
FontName: "Шрифт(&F)",
FontSize: "Размер шрифта(&S)",
AntiAliasing: "Сглаживание(&A)",
None: "Нет",
Sharp: "Острее",
Crisp: "Чётче",
Strong: "Сильнее",
Smooth: "Глаже",
Color: "Цвет",
Color0: "Будней(&W)",
Color1: "Выходных(&D)",
Vertical: "Вертикально(&V)",
Horizontal: "Горизонтально(&H)",
Indent: "Отступ(&I)",
Language: "Язык(&L)",
Ok: "OK",
Cancel: "Отмена",
Pixels: "пикселей",
Points: "точек",
MM: "мм.",
IncorrectValue: "Неправильное значение",
DaysOfWeek: "Дни недели",
Dates: "Числа"
}
break;
default:
this.str = {
Title: "Calendar",
Date: "Date",
Month: "&Month",
Year: "&Year",
Parameters: "Parameters",
FontName: "&Font",
FontSize: "Font &size",
AntiAliasing: "&Antialiasing method",
None: "None",
Sharp: "Sharp",
Crisp: "Crisp",
Strong: "Strong",
Smooth: "Smooth",
Color: "Color",
Color0: "&Work days",
Color1: "Holi&days",
Vertical: "&Vertical",
Horizontal: "&Horizontal",
Indent: "&Indent",
Language: "&Language",
Ok: "OK",
Cancel: "Cancel",
Pixels: "pixels",
Points: "points",
MM: "mm.",
IncorrectValue: "Incorrect Value",
DaysOfWeek: "Days of a week",
Dates: "Dates"
}
}
// strings which are contents of the document
this.str.docLang = [
["русский",
["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
["пн", "вт", "ср", "чт", "пт", "сб", "вс"]
],
["english",
["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
["mo", "tu", "we", "th", "fr", "sa", "su"]
],
["deutsch",
["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "October", "November", "Dezember"],
["mo", "di", "mi", "do", "fr", "sa", "so"]
],
["française",
["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"],
["lu", "ma", "me", "je", "ve", "sa", "di"]
],
["el español",
["Enero de", "Febrero de", "Marzo de", "Abril de", "Mayo de", "Junio de", "Julio de", "Agosto de", "Septiembre de", "Octubre de", "Noviembre de", "Diciembre de"],
["lu", "ma", "mi", "ju", "vi", "sá", "do"]
],
["italiano",
["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"],
["lu", "ma", "me", "gi", "ve", "sa", "do"]
]
].sort();
// set units of measure
switch (app.preferences.typeUnits) {
case TypeUnits.MM: app.preferences.rulerUnits = Units.MM; var u = this.str.MM; break;
case TypeUnits.POINTS: app.preferences.rulerUnits = Units.POINTS; var u = this.str.Points; break;
default: app.preferences.rulerUnits = Units.PIXELS; var u = this.str.Pixels;
}
// create a script UI with placed parameters values
this.dlgMain = new Window("dialog { \
orientation: 'column', alignChildren: 'fill', \
p0: Panel { margins: [10, 15, 10, 10], alignChildren: 'right', text: '" + this.str.Date + "', \
g0: Group { orientation: 'row', spacing: 5, \
l0: StaticText { text: '" + this.str.Month + ":' } \
t0: EditText { preferredSize: [45, 20], text: '" + (1+n.getMonth()) + "' } \
l1: StaticText { text: ' " + this.str.Year + ":' } \
t1: EditText { preferredSize: [45, 20], text: '" + n.getFullYear() + "' } } \
g1: Group { orientation: 'row', spacing: 5, \
l: StaticText { text: '" + this.str.Language + ":' } \
s: DropDownList { preferredSize: [80, 22] } } } \
p1: Panel { margins: [10, 15, 10, 10], alignChildren: 'right', text: '" + this.str.Parameters + "', \
g0: Group { orientation: 'row', spacing: 5, \
l: StaticText { text: '" + this.str.FontName + ":' } \
s: DropDownList { preferredSize: [165, 22] } } \
g1: Group { orientation: 'row', spacing: 5, \
l: StaticText { text: '" + this.str.FontSize + ":' } \
t: EditText { preferredSize: [40, 20], fractionalOpportunity: true, text: '" + this.params.FontSize.toString().replace(/\./g, ',') + "' } \
u: StaticText { text: '" + u + "' } } \
g2: Group { orientation: 'row', spacing: 5, \
l: StaticText { text: '" + this.str.AntiAliasing + ":' } \
s: DropDownList { preferredSize: [80, 22] } } \
g3: Group { orientation: 'row', spacing: 5,\
l: StaticText { text: '" + this.str.Color + ":' } \
b0: Button { preferredSize: [80, 22], text: '" + this.str.Color0 + "', helpTip: '" + this.params.Color0 + "' } \
b1: Button { preferredSize: [80, 22], text: '" + this.str.Color1 + "', helpTip: '" + this.params.Color1 + "' } } \
g4: Group { orientation: 'row', spacing: 5, \
r0: RadioButton { value: " + this.params.VerticalDirection + ", text: '" + this.str.Vertical + "' } \
r1: RadioButton { value: " + !this.params.VerticalDirection + ", text: '" + this.str.Horizontal + "' } } \
g5: Group { orientation: 'row', spacing: 5, \
l: StaticText { text: '" + this.str.Indent + ":' } \
s: Slider { value: " + this.params.IncreaseIndent + ", minvalue: 0.5, maxvalue: 10 } \
t: EditText { preferredSize: [113, 20], fractionalOpportunity: true, text: '" + this.params.IncreaseIndent.toString().replace(/\./g, ',') + "' } } } \
btns: Group { alignment: 'right', margins: [0, 10, 0, 0] } \
}", this.str.Title);
var d = this.dlgMain;
for (var i = 0; i < this.str.docLang.length; i++) {
d.p0.g1.s.add("item", this.str.docLang[i][0]);
if (this.str.docLang[i][0] == "русский") d.p0.g1.s.selection = i;
}
if (d.p0.g1.s.selection == null) d.p0.g1.s.selection = 0;
// update font list
app.refreshFonts();
for (var i = 0; i < app.fonts.length; i++) {
d.p1.g0.s.add("item", app.fonts[i].name);
if (app.fonts[i].postScriptName == this.params.FontName) d.p1.g0.s.selection = i;
}
if (d.p1.g0.s.selection == null) d.p1.g0.s.selection = 0;
this.params.FontName = app.fonts[d.p1.g0.s.selection.index].postScriptName;
d.p1.g2.s.add("item", this.str.None);
d.p1.g2.s.add("item", this.str.Sharp);
d.p1.g2.s.add("item", this.str.Crisp);
d.p1.g2.s.add("item", this.str.Strong);
d.p1.g2.s.add("item", this.str.Smooth);
switch (this.params.AntiAlias) {
case "AntiAlias.NONE": d.p1.g2.s.selection = 0; this.params.AntiAlias = AntiAlias.NONE; break;
case "AntiAlias.SHARP": d.p1.g2.s.selection = 1; this.params.AntiAlias = AntiAlias.SHARP; break;
case "AntiAlias.CRISP": d.p1.g2.s.selection = 2; this.params.AntiAlias = AntiAlias.CRISP; break;
case "AntiAlias.STRONG": d.p1.g2.s.selection = 3; this.params.AntiAlias = AntiAlias.STRONG; break;
case "AntiAlias.SMOOTH": d.p1.g2.s.selection = 4; this.params.AntiAlias = AntiAlias.SMOOTH; break;
}
d.p1.g5.s.preferredSize.width = 40;
d.p1.g5.s.helpTip = (d.p1.g5.s.value < 0) ? "-" : "";
d.p1.g5.s.helpTip += d.p1.g5.s.value.toString().replace(/\./g, ",");
d.defaultElement = d.btns.add("button", undefined, this.str.Ok);
d.cancelElement = d.btns.add("button", undefined, this.str.Cancel);
d.graphics.backgroundColor = d.graphics.newBrush(d.graphics.BrushType.THEME_COLOR, "appDialogBackground");
// descriptions of the event handlers
d.p0.g0.t0.addEventListener("keydown", NumericEditKeyboardHandler);
d.p0.g0.t1.addEventListener("keydown", NumericEditKeyboardHandler);
d.p1.g1.t.addEventListener("keydown", NumericEditKeyboardHandler);
d.p1.g5.t.addEventListener("keydown", NumericEditKeyboardHandler);
d.p1.g0.s.onChange = function() {
gCalendar.params.FontName = app.fonts[this.selection.index].postScriptName;
}
d.p1.g2.s.onChange = function() {
switch (this.selection.index) {
case 0: gCalendar.params.AntiAlias = AntiAlias.NONE; break;
case 1: gCalendar.params.AntiAlias = AntiAlias.SHARP; break;
case 2: gCalendar.params.AntiAlias = AntiAlias.CRISP; break;
case 3: gCalendar.params.AntiAlias = AntiAlias.STRONG; break;
case 4: gCalendar.params.AntiAlias = AntiAlias.SMOOTH; break;
}
}
d.p1.g3.b0.onClick = function() {
app.foregroundColor.rgb.hexValue = gCalendar.params.Color0;
if (app.showColorPicker()) gCalendar.params.Color0 = this.helpTip = app.foregroundColor.rgb.hexValue;
}
d.p1.g3.b1.onClick = function() {
app.foregroundColor.rgb.hexValue = gCalendar.params.Color1;
if (app.showColorPicker()) gCalendar.params.Color1 = this.helpTip = app.foregroundColor.rgb.hexValue;
}
d.p1.g4.r0.onClick = function() {
gCalendar.params.VerticalDirection = true;
}
d.p1.g4.r1.onClick = function() {
gCalendar.params.VerticalDirection = false;
}
d.p1.g5.s.onChange = function() {
var t = this.value.toString().replace(/\./g, ",");
this.helpTip = (this.value < 0) ? "-" : "";
this.helpTip += t;
this.parent.t.text = t;
gCalendar.params.IncreaseIndent = this.value;
}
d.p1.g5.t.onChange = function() {
var t = parseFloat(this.text.replace(/\,/g, "."));
if (isNaN(t) || t < this.parent.s.minvalue || t > this.parent.s.maxvalue) {
d.p1.g5.s.value = t;
this.parent.s.helpTip = (t < 0) ? "-" : "";
this.parent.s.helpTip += this.text;
gCalendar.params.IncreaseIndent = this.parent.s.value;
}
}
d.defaultElement.onClick = function() {
var m = parseInt(d.p0.g0.t0.text), y = parseInt(d.p0.g0.t1.text);
gCalendar.params.FontSize = parseFloat(d.p1.g1.t.text.replace(/,/g, "."));
gCalendar.params.IncreaseIndent = parseFloat(d.p1.g5.t.text.replace(/,/g, "."));
if (!isNaN(m) && m > 0 && m < 13) n.setMonth(--m);
else {
d.p0.g0.t0.active = true;
alert(gCalendar.str.IncorrectValue + ".");
return;
}
if (!isNaN(y) && y > 1900 && d.p0.g0.t1.text.length < 5) n.setFullYear(y);
else {
d.p0.g0.t1.active = true;
alert(gCalendar.str.IncorrectValue + ".");
return;
}
if (isNaN(gCalendar.params.FontSize) || gCalendar.params.FontSize <= 0) {
d.p1.g1.t.active = true;
alert(gCalendar.str.IncorrectValue + ".");
return;
}
if (isNaN(gCalendar.params.IncreaseIndent) || gCalendar.params.IncreaseIndent < d.p1.g5.s.minvalue || gCalendar.params.IncreaseIndent > d.p1.g5.s.maxvalue) {
d.p1.g5.t.active = true;
alert(gCalendar.str.IncorrectValue + ".");
return;
}
d.close(true); // return 1 if changed values have been checked successfully
}
d.cancelElement.onClick = function() {
d.close(false); // return 0
}
// function of processing of the document
this.Make = function() {
n.setDate(1);
n.setHours(12);
var x = n.getDay();
if (x == 0) x = 7;
var w = 0, h = 0, c = SolidColor;
c.rgb.hexValue = this.params.Color0;
var doc = app.documents.add(8 * this.params.IncreaseIndent * this.params.FontSize, 8 * this.params.IncreaseIndent * this.params.FontSize, 72, this.str.Title + "_" + (1+n.getMonth()) + "_" + n.getFullYear(), NewDocumentMode.RGB, DocumentFill.TRANSPARENT);
var gr = [];
gr[0] = doc.layerSets.add();
gr[0].name = this.str.Title;
gr[1] = gr[0].layerSets.add();
gr[1].name = this.str.Dates;
gr[2] = gr[0].layerSets.add();
gr[2].name = this.str.DaysOfWeek;
var l = doc.artLayers[0];
l.isBackgroundLayer = false;
l.move(gr[0], ElementPlacement.PLACEATBEGINNING);
l.kind = LayerKind.TEXT;
with (l.textItem) {
position = [doc.width.value / 2, doc.height.value / 8 - doc.height.value / 32];
justification = Justification.CENTER;
font = this.params.FontName;
size = this.params.FontSize * 1.25;
antiAliasMethod = this.params.AntiAlias;
color = c;
fauxBold = true;
contents = this.str.docLang[d.p0.g1.s.selection.index][1][n.getMonth()] + " " + n.getFullYear();
}
for (var i = 0; i < 7; i++) {
w = (this.params.VerticalDirection) ? 0 : doc.width.value / 7 * i;
h = (this.params.VerticalDirection) ? doc.height.value / 8 * (i + 2) : doc.height.value / 4;
l = gr[2].artLayers.add();
l.kind = LayerKind.TEXT;
with (l.textItem) {
position = [w + doc.width.value / 14, h - doc.height.value / 32];
justification = Justification.CENTER;
font = this.params.FontName;
size = this.params.FontSize * 0.75;
antiAliasMethod = this.params.AntiAlias;
c.rgb.hexValue = (i > 4) ? this.params.Color1 : this.params.Color0;
color = c;
contents = this.str.docLang[d.p0.g1.s.selection.index][2][i];
}
}
for (var i = 1, p = 2; parseInt(d.p0.g0.t0.text) > n.getMonth(); i++) {
w = (this.params.VerticalDirection) ? doc.width.value / 7 * (p - 1) : doc.width.value / 7 * (x + i - 2);
h = (this.params.VerticalDirection) ? doc.height.value / 8 * (x + i) : doc.height.value / 8 * (p + 1);
l = gr[1].artLayers.add();
l.kind = LayerKind.TEXT;
with (l.textItem) {
position = [w + doc.width.value / 14, h - doc.height.value / 32];
justification = Justification.CENTER;
font = this.params.FontName;
size = this.params.FontSize;
antiAliasMethod = this.params.AntiAlias;
c.rgb.hexValue = (x + i > 6) ? this.params.Color1 : this.params.Color0;
color = c;
contents = i;
}
if (x + i > 7) {
++p;
x -= 7;
}
n.setDate(1 + i);
}
doc.resizeCanvas(doc.width.value + this.params.FontSize, doc.height.value + this.params.FontSize, AnchorPosition.MIDDLECENTER);
doc.activeLayer = gr[0];
// save parameters in the file
if (!this.paramsFile.readonly) {
this.paramsFile.encoding = "UTF8";
if (this.paramsFile.open("w", "TEXT", "????")) {
this.paramsFile.write("\uFEFF");
this.paramsFile.writeln("Version=" + this.Version);
for (var p in this.params) this.paramsFile.writeln(p + "=" + this.params[p]);
this.paramsFile.close();
}
}
}
}
function NumericEditKeyboardHandler(event) { // keyboard event handler for a numeric input only
try {
var code = parseInt("0x" + event.keyIdentifier.substr(2));
if (! (KeyIsNumeric(event, code) || KeyIsCommaOrPeriod(event, code) || KeyIsLRArrow(event) || KeyIsDelete(event) || KeyIsTabEnterEscape(event))) event.preventDefault();
} catch(e) {}
}
function KeyHasModifier(event) {
return event.shiftKey || event.ctrlKey || event.altKey || event.metaKey;
}
function KeyIsNumeric(event, code) {
return code >= 48 && code <= 57 && !KeyHasModifier(event);
}
function KeyIsCommaOrPeriod(event, code) {
return (code == 44 || code == 46) && !KeyHasModifier(event) && event.target.fractionalOpportunity && event.target.text.indexOf(",") == -1 && event.target.text.indexOf(".") == -1;
}
function KeyIsLRArrow(event) {
return (event.keyName == "Left" || event.keyName == "Right") && ! (event.altKey || event.metaKey);
}
function KeyIsDelete(event) {
return (event.keyName == "Backspace" || event.keyName == "Delete") && !event.ctrlKey;
}
function KeyIsTabEnterEscape(event) {
return event.keyName == "Tab" || event.keyName == "Enter" || event.keyName == "Escape";
}
try {
// keep a some preferences
uDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
uUnits = app.preferences.rulerUnits;
uForegroundColor = app.foregroundColor.rgb.hexValue;
// create global object
gCalendar = new Calendar();
if (gCalendar.dlgMain.show() == 1) {
gCalendar.Make();
app.bringToFront();
}
// set the kept preferences
app.preferences.rulerUnits = uUnits;
app.foregroundColor.rgb.hexValue = uForegroundColor;
app.displayDialogs = uDialogMode;
// cleaned from objects
gCalendar = null;
uDialogMode = null;
uUnits = null;
uForegroundColor = null;
} catch(e) {}
После использования скрипта сохраняются последние шрифт, размер и т.д. в "%AppData%\Adobe\Adobe Photoshop ...\Adobe Photoshop ... Settings\script_params_calendar.txt"


Помощь
Оффлайн
Инфо (45)











