Skip navigation
Currently Being Moderated

[JS][CS4] - populating a drop down with list of printers?

Mar 27, 2012 9:04 AM

Tags: #illustrator #printer #javacsript #printerlist

Hello,

 

I'm trying to populate a drop down field with the list of available printers. Here's what I have:

 

var printerList = app.printerList;

 

var w = new Window ("dialog");
w.orientation = 'row';
var dropDown = w.add("statictext", undefined, "Please select the printer");
var dropDown = w.add ("dropdownlist", undefined, printerList);
dropDown.selection = 0;
var buttonGroup = w.add ("group");
buttonGroup.add ("button", undefined, "OK");
w.center();
w.show();

This will populate a drop down with "Printer, Printer, Printer, Printer" for each printer instead of the name of the printer (which is what I want).

 

When I try:

 

var printerList = app.printerList.name;

 

I get a drop down of blank entries.

 

Any ideas on what I'm doing wrong?  How exactly does the printerList work?

 

Thanks,

Lindsay

 
Replies
  • Currently Being Moderated
    Mar 27, 2012 9:53 AM   in reply to booyajamo

    When I run the script that you have in the box above I get

     

    Screen shot 2012-03-27 at 9.48.24 AM.png

     

    Is this not what you get? Try commenting out the first var setting the printerList and target illustrator like this

     

     

    #target illustrator
     
    //var printerList = app.printerList.Printer.name;
     
    var w = new Window ("dialog");
    w.orientation = 'row';
    var dropDown = w.add("statictext", undefined, "Please select the printer");
    var dropDown = w.add ("dropdownlist", undefined, printerList);
    dropDown.selection = 0;
    var buttonGroup = w.add ("group");
    buttonGroup.add ("button", undefined, "OK");
    w.center();
    w.show();
    
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 27, 2012 5:25 PM   in reply to booyajamo

    What OS? It appears a PC; I'm on a Mac. Maybe that's the difference.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 28, 2012 8:28 AM   in reply to booyajamo

    in that thread example, I added this two lines to write the names to an array

     

    var arrayPrinterNames = []; // added
    for (var i = 0; i < iCount; ++i) {
              arrayPrinterNames.push(app.printerList[i].name); // added
    
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 29, 2012 12:13 AM   in reply to CarlosCanto

    it also takes forever in my system, so I would add the following line

     

    var pL = app.printerList;
    

     

    and use pL to avoid multiple calls to the system. for example

     

    var arrayPrinterNames = [];
    for (var i = 0; i < iCount; ++i) {
              arrayPrinterNames.push(pL[i].name);
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points