0

Could someone please show me how to simply print photoshop document using Extendscript Javascript?

Current lines are:

var doc = app.activeDocument;

var array = [
"Name Surname 1",
"Name Surname 2",
"Name Surname 3"
];

for( var i = 0; i < array.length; i++){
    changeTextByLayerName("name-surname-layer", array[i]);
    doc.print(); // <<< here script is crashing
    $.sleep(2000);
    $.wirteln(i + " " + array[i] + " is printed");

}

function changeTextByLayerName(layerName,newText){
    var layer = doc.layers.getByName(layerName);
    if(layer.kind == LayerKind.TEXT) layer.textItem.contents = newText;
}

Using Adobe Photoshop CC on Mac OS X 10.9.1

Rozkalns
  • 510
  • 2
  • 6
  • 26
  • do you have valid print settings? – Anna Forrest Dec 18 '13 at 18:37
  • Sorry, but I don't have any idea :) I just want to be a little bit lasy and I don't want to repeat the same 100 times over and over again :) Or previous sentences just means that I started to get my hands dirty with ExtendScript just 4 hours ago, so... :) – Rozkalns Dec 18 '13 at 18:39
  • Well, I suggest you start by putting a break point in above doc.print() and inspecting the printer settings currently set in doc.printerSettings. Specifically the obvious things like the printer name and make sure it is set to something suitable. If that doesn't get you anywhere, what is the actual error you are getting? – Anna Forrest Dec 18 '13 at 21:21

1 Answers1

0

In the CS5 documentation I can find a print command for a Document, but I don't know what the parameters are for. Fortunately, they all seem optional, so you can try this anyway:

doc.print();

at the end of your script.

There doesn't seem to be a way to set the "current printer" or any of its properties such as paper size or orientation. It may lurk somewhere under a not-so-obvious name or object (Adobe is known to do so), or the print command itself may call up the dialog. Nevertheless, if it does all that's required is a hit on the ol' OK button.

As Anna Forest points out, it's there: http://jongware.mit.edu/pscs5js_html/psjscs5/pc_DocumentPrintSettings.html

Perhaps the problem lies somewhere in the print settings. Try using Print from the interface itself to see if it is your printer driver instead.

Jongware
  • 22,200
  • 8
  • 54
  • 100
  • In CS6, Document has a PrintSetting object which in turn has a 'printerName' property. – Anna Forrest Dec 18 '13 at 21:19
  • @AnnaForrest: you are right! It's also in the CS5 version I pointed to: http://jongware.mit.edu/pscs5js_html/psjscs5/pc_DocumentPrintSettings.html (with a footnote to the OP: versions *can* make a huge difference. Hopefully, not too much changed for CC). – Jongware Dec 18 '13 at 21:22