Indesign scripting: printer presets

Scripting printer presets

[Di questo articolo esiste la versione in italiano]

Printer presets are accessible to Indesign scripting by the object collection PrinterPresets.

We will see some elementary examples from the ESTK (Extendscript Toolkit) console, the development environment installed by default in Indesign.

Obviously the properties and methods accessible are many more than this, you can get a complete reference here or in Adobe documentation.

Get to coding:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//how many presets in INDD
number_presets=app.printerPresets.length;
//print result in ESTK console
$.write("Installed presets n.",number_presets);
//print presets names
$.write("Their names are:\n");
for (j=0;j<number_presets;j++)
{
    mypreset=app.printerPresets.[j];
    $.write(mypreset.name);
}
//print to console the printer defined in the preset
$.write("Printer defined in the presets are:\n");
for (j=0;j<number_presets;j++)
{
    mypreset=app.printerPresets.[j];
    $.write(mypreset.printer);
}
//print to console the paper size defined in the preset
$.write("Paper size set is:\n");
for (j=0;j<number_presets;j++)
{
    mypreset=app.printerPresets.[j];
    $.write(mypreset.paperSize);
}

Results in the console will be this kind (image taken from italian ID):

where, for example you can see that the “[Predefinito]” preset uses the “Samsung ML-3050 Series” printer, as that named “Predefinito di stampa 1” uses the “1886611052” printer (which is the ID internal code for the special printer “Postscript File”).

A minimal graphical UI

If you prefer testing these properties with a minimal garphical interface, here you are. In this case you have to save the script in the Indesign Scripts Panel folder and launch it from the Scripts panel in Indesign.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
var myPresets = app.printerPresets.everyItem().name;
var w = new Window ("dialog");
w.text="Printer Presets";
w.orientation = 'row';
var myDropDown = w.add ("statictext", undefined, "Printer Presets");
var myDropDown = w.add ("dropdownlist", undefined, myPresets);
myDropDown.selection = 0;
var myButtonGroup =  w.add ("group");
myButtonGroup.add ("button", undefined, "OK");
w.center();
w.show();
preset=app.printerPresets.[myDropDown.selection.index];
preset_name=preset.name;
mess1="You selected: "+preset.name+"\n";
mess2="The selected preset printer is: "+preset.printer+"\n";
mess3="The selected preset paper size is: "+preset.paperSize+"\n";
alert(mess1+mess2+mess3);

You should see the following dialogs.