• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is there an easier way?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there an easier way?


  • Subject: Re: Is there an easier way?
  • From: Stan Cleveland <email@hidden>
  • Date: Thu, 04 Dec 2014 13:26:57 -0800

On Dec 4, 2014, at 11:51 AM, Brian Christmas <email@hidden> wrote:

Thanks Stan, but there appears to be something wrong with your last shell script. (it’s 6:49 am in Oz, and I’ve been up all night, so I hope my code is correct).

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

Hi Brian,

First of all, the final parameter for the 'lpoptions' command should be "-l" (lower-case "L") not "-p".

Also, I'm not sure why you're building strings for printerList and pageLists, but, as such, you can't repeat through them. You could repeat through paragraphs of those strings, but why not just set them up as lists to start with? 

Using your code as a basis, below is how I'd simplify things, more or less. Sorry if the record returned is not what you need—you may need to rearrange the data.

Regards,
Stan C.

set printerList to paragraphs of (do shell script "lpstat -a")
set pageSizeList to {}
repeat with i from 1 to (count printerList)
set printerName to word 1 of item i of printerList
set pageSizeText to do shell script ("lpoptions -p " & printerName & " -l | grep 'PageSize'")
set pageSizes to words of text 22 thru -1 of pageSizeText -- remove "PageSize/Media Size: "
set end of pageSizeList to {printerName:printerName, pageSizes:pageSizes}
end repeat
return pageSizeList

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
applescriptobjc-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Is there an easier way?
      • From: Brian Christmas <email@hidden>
References: 
 >Is there an easier way? (From: Brian Christmas <email@hidden>)
 >Re: Is there an easier way? (From: Stan Cleveland <email@hidden>)
 >Re: Is there an easier way? (From: Brian Christmas <email@hidden>)

  • Prev by Date: Re: Is there an easier way?
  • Next by Date: Re: Is there an easier way?
  • Previous by thread: Re: Is there an easier way?
  • Next by thread: Re: Is there an easier way?
  • Index(es):
    • Date
    • Thread