Skip to main content
c.pfaffenbichler
Community Expert
Community Expert
January 19, 2010
Answered

printSettings.activePrinter not writeable in JS on Mac and CS4

  • January 19, 2010
  • 1 reply
  • 4006 views

Somehow I feel this may have come up before, but I can’t find anything, so:

According to »Photoshop CS4 JavaScript Ref.pdf«

app.activeDocument.printSettings.activePrinter

should be read-write, but I fail to be able to change the active printer (Mac OS X 10.5.8 and Photoshop 11.0.1).

Do any of You know if there is a known issue or have an idea what I could be overlooking?

This topic has been closed for replies.
Correct answer Muppet Mark

Cool, cool stuff.

I had so far not looked into Scripting for Bridge itself and Unix is beyond me …

Unfortunately I can’t seem to make it work for my purposes.

For use in a Photoshop-Script I suppose I would have to address Bridge via BridgeTalk and set the Default Printer, and this seems to work fine … unfortunately Photoshop does not seem to care about the Default Printer, but will print to the one last used from Photoshop itself.


I only got a s far as seeing if this was a possibility and this did work for me here. I set up a bunch of fake IP printers to test (half dozen).

I could then keep changing the index of the printerList array and each time this was the selected printer in the print dialog.

Printing added to the correct spoolers. What I think you may have to do is NOT have last used selected in system prefs.

This requires a little cleaning up as I cheated with the bridgetalk message for now. Don't know why filePath.remove(); is NOT working either will have to look at that too (could use shell rm but don't think I need to). Here is my rough test script…

#target photoshop

// Get current system default printer name

var defaultPrinter = osxGetDefaultPrinter();

// Get list of available system printers

var printerList = osxAvailablePrinters();

// Set system default to choice

osxSetDefaultPrinter(printerList[2]);

function osxGetDefaultPrinter() {

var shellString = "lpstat -d | awk '{print $4}' > ~/Desktop/OSX_Default_Printer.txt";

btMessaging('bridge', shellString);

var filePath = new File('~/Desktop/OSX_Default_Printer.txt');

var defaultPrinter;

filePath.open('r');

while (filePath.tell() < filePath.length) {

var defaultPrinter = filePath.readln();

}

filePath.close();

filePath.remove();

return defaultPrinter;

}

function osxAvailablePrinters() {

var shellString = "lpstat -a | awk '{print $1}' > ~/Desktop/OSX_Available_Printers.txt";

btMessaging('bridge', shellString);

var filePath = new File('~/Desktop/OSX_Available_Printers.txt');

var printerList = new Array();

filePath.open('r');

while (filePath.tell() < filePath.length) {

printerList.push(filePath.readln());

}

filePath.close();

filePath.remove();

return printerList;

}

function osxSetDefaultPrinter(printerName) {

var shellString = "lpoptions -d " + printerName;

btMessaging('bridge', shellString);

}

function btMessaging(targetApp, script) {

var bt = new BridgeTalk();

bt.target = targetApp;

bt.body = 'app.system(' + script.toSource() + ');';

//bt.onResult = function(inBT) {}

//bt.onError = function(inBT) {}

bt.send();

}

Get default printer could be recalled as a test as using bridge system commands don't return anything.

1 reply

Inspiring
January 19, 2010

I just did a test for you and I can't change it on WindowsXP either.

Also, at least on WindowsXP, the printer return is not the printer the document is using but the system default printer. For example my test document has Acrobat as the printer and the system default is an Epson. activePrinter returns the Epson, but when I print the doc it prints to PDF.

A quick check of the document's descriptor doesn't show any keys that are print related.

c.pfaffenbichler
Community Expert
Community Expert
January 19, 2010

Thanks.

Another recent thread had turned my attention to printing with Scripts and I seem to remember that I hadn’t gotten anywhere with it when attempting it some time ago …

On my station it at least seems to display the actually selected printer, but changing it doesn’t work.

Muppet_Mark-QAl63s
Inspiring
January 20, 2010

What was it that you wanted script to do with printing/printers?