Hi, everyone
I got this script,
#target indesign
// change chosen version of indents of paragraph
// based on text selected by user
// dialog with format examples (edit properties inside mDialog() function )
app.doScript('main()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Change Indents");
function mDialog()
{ // user choice
var
w = new Window("dialog","Change paragraphs' Indents", undefined, {closeButton: false}),
stringList = [ "01 indent (00, 00)",//0
"02 indent (08, 00)",//1
"03 indent (16, 00)",//2
"04 indent (24, 00)",//3
"05 indent (32, 00)",//4
"06 indent (40, 00)",//5
"-", //6
"07 indent (00, 08)",//7
"08 indent (08, 08)",//8
"09 indent (16, 08)",//9
"10 indent (24, 08)",//10
"11 indent (32, 08)",//11
"12 indent (40, 08)",//12
"-", //13
"21 indent (08, -8)",//14
"22 indent (16, -8)",//15
"23 indent (24, -8)",//16
"24 indent (32, -8)",//17
"25 indent (40, -8)",//18
"26 indent (48, -8)"],//19
mReminderString = "XXXXXX",
lastSelected = Number(app.extractLabel("dialogIndents") ),
p = w.add("panel", undefined, "Choose a version of indent"),
mDD = p.add("dropdownlist", undefined, stringList),
mRem = p.add("statictext", undefined, mReminderString, {multiline: true} ),
b = w.add("group");
mDD.preferredSize = [200,23];
if ( !lastSelected ) mDD.items[0].selected = true;
else mDD.items[lastSelected].selected = true;
// |||||||||||||||||||||||||||||||||||||||||||||||| modify reminder font here |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
w.graphics.backgroundColor = w.graphics.newBrush (w.graphics.BrushType.SOLID_COLOR, [0.3, 0.5, 0.8]);
mRem.alignment = "left";
mRem.graphics.font = ScriptUI.newFont ("Arial", "Bold", 10);
mRem.graphics.foregroundColor = mRem.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [1, 1, 1], 1);
p.graphics.font = ScriptUI.newFont ("Arial", "Bold", 13);
p.graphics.foregroundColor = mRem.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [1, 1, 1], 1);
mDD.graphics.font = ScriptUI.newFont ("Arial", "Bold", 12);
mDD.graphics.foregroundColor = mRem.graphics.newPen (w.graphics.PenType.SOLID_COLOR, [0.3, 0.5, 0.8], 1);
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||
b.add ('iconbutton', undefined, File ("~/Desktop/macicon.png"), {name: "OK"}); // no vaild need to fix
b.add ('button', undefined, "ยกเลิก ", {name: "Cancel"});
if (w.show() ==1 ) {
app.insertLabel("dialogIndents", String(mDD.selection.index) );
return mDD.selection.index;
}
else exit();
}
function checkSelection()
{ // alert if wrong selection, set target
var mMsg = "Can't do any job\rSelect some text as a target or place cursor inside target paragraph";
if ( !app.documents.length || !app.selection.length) {
alert (mMsg);
exit();
}
var curObj = app.selection[0];
do {
if (app.selection[0].hasOwnProperty ("contents") ) return curObj;
curObj = curObj.parent;
}
while (curObj.constructor.name != "Spread")
alert (mMsg);
exit();
}
function main()
{ // starter
indents( checkSelection(), mDialog() );
}
function indents(myObject, myChoice)
{ // job function
switch (myChoice) {
case 0:
//set Indent of selected text //0
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 0;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 0;
}
break;
case 1:
//set Indent of selected text//1
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 0;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 8;
}
break;
case 2:
//set Indent of selected text//2
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 0;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 16;
}
break;
case 3:
//set Indent of selected text//3
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 0;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 24;
}
break;
case 4:
//set Indent of selected text//4
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 0;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 32;
}
break;
case 5:
//set Indent of selected text//5
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 0;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 40;
}
break;
case 6:
break;
case 7:
//set Indent of selected text//6
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 0;
}
break;
case 8:
//set Indent of selected text//7
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 8;
}
break;
case 9:
//set Indent of selected text//8
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 16;
}
break;
case 10:
//set Indent of selected text//9
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 24;
}
break;
case 11:
//set Indent of selected text//10
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 32;
}
break;
case 12:
//set Indent of selected text//11
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = 8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 40;
}
break;
case 13:
break;
case 14:
//set Indent of selected text//13
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = -8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 8;
}
break;
case 15:
//set Indent of selected text//14
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = -8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 16;
}
break;
case 16:
//set Indent of selected text//15
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = -8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 24;
}
break;
case 17:
//set Indent of selected text//16
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = -8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 32;
}
break;
case 18:
//set Indent of selected text//17
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = -8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 40;
}
break;
case 19:
//set Indent of selected text//18
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].firstLineIndent = -8;
}
if (app.selection.length && app.selection[0].hasOwnProperty("baseline")) {
app.selection[0].leftIndent = 48;
}
break;
default: break;
}
}
but how can I make the iconbutton functioning?
thanks
Regard
Teetan