I was already using the -a option to get a list of printers, but page lists have eluded me, especially when there are many secondary paper menus on my two printers when using text edit (like ‘A4 without margins').
My code as below returns gobbledygook, and if I uncomment the last line, I get an error. Are you aware of any problems?
set wholePrinterList to item 1 of ((do shell script "lpstat -a") & return as list)
set findCharacter to (character id 13)
set printerList to "No Printer Selected" & return as text
set printerList to ""
if (count of wholePrinterList) > 0 then
repeat
set nameOfEachPrinter to characters 1 through ((offset of " " in (wholePrinterList as text)) - 1) of (wholePrinterList as text) as text
set printerList to printerList & nameOfEachPrinter & return
set theNextReturn to offset of findCharacter in (wholePrinterList as text)
if theNextReturn < (count of wholePrinterList) then
set wholePrinterList to characters (theNextReturn + 1) through (count of wholePrinterList) of (wholePrinterList as text) as text
else
exit repeat
end if
end repeat
end if
set pageLists to ""
repeat with x from 1 to (count of printerList)
set eachPrinter to item x of printerList as text
set pageLists to pageLists & (do shell script "lpoptions -p " & eachPrinter & " -p" & return & return)
end repeat
printerList & return & return & pageLists
#do shell script "lpoptions -p EPSON_Artisan_730 -p”
returns…
"EPSON_Artisan_730
Quark_Printer
rtfd_Printer
ËsmˇË>tnˇË~C`ˇËlˇËN≤nˇËbˇËÉjˇË>ÅmˇËû¢dˇËû¿jˇË.∂hˇËÓ¶cˇËnSoˇËŒ‚bˇËû%cˇËé˚iˇËƘbˇËÓıaˇËfi£jˇËfi.dˇË>πiˇËbˇËæË^fijˇËÓ°dˇË£nˇËNŸnˇËÍgˇËæÑfˇËìgˇËûrfˇË^ªkˇË˛£iˇË˛ÒfˇË˛ÑmˇËŒíkˇË˛lhˇËn§cˇËÓfljˇËûdˇËŒfdˇËŒonˇËŒ=aˇËfi/kˇË.ådˇ”
Uncomment the last line, and this error occurs…
error "Usage: lpoptions [-h server] [-E] -d printer
lpoptions [-h server] [-E] [-p printer] -l
lpoptions [-h server] [-E] -p printer -o option[=value] ...
lpoptions [-h server] [-E] -x printer" number 1
On 5 Dec 2014, at 5:04 am, Stan Cleveland <
email@hidden> wrote:
On Dec 4, 2014, at 7:36 AM, Brian Christmas <
email@hidden> wrote:
I’m trying to build a list of every paper size available to any given printer, set from a printer list of existing printers.
I’m using the print dialog box from Text Edit, with the code below.
It’s very slow, so I’m wondering if there’s any way of obtaining the list without opening every paper menu?
Any help appreciated.
Hi Brian,
You could use 'do shell script' and parse the text returned by the following two shell commands.
This gives you a listing of "Unix" names for every printer set up on your computer:
lpstat -p
This lists
all printer options, including paper sizes. Put your "Unix" printer name in place of mine, in
red:
lpoptions -p Canon_iR_ADV_C9000s_A1_PSV1_0US -p
Below is the
PageSize/Media Size portion of the result of the latter command on my system. It's all in one line. The
Custom.WIDTHxHEIGHT entry indicates that custom page sizes are supported. The page size that's preceded by an asterisk is the default page size.
PageSize/Media Size: Custom.WIDTHxHEIGHT *Letter Legal Tabloid Executive Statement A3 A4 A5 B5 B4 Monarch Com10 DL C5 ISOB5 SRA3 12x18 13x19 13x19_MAX
HTH,
Stan C.