I created a folder action script that asked the user to choose a printer from a list of currently-installed printers, so that I could get the name of the printer and the name of the printer queue, using this code (built from suggestions generously provided in this forum):
set thePrinter to ""
set theQueue to ""
set printerNames to (do shell script "lpstat -l -p | grep -i Description: |awk -F'Description: ' '{print $2}' ")
set queueNames to (do shell script "lpstat -a | awk -F' accepting' '{print $1}'")
set printerList to (every paragraph of printerNames) as list
set queueList to (every paragraph of queueNames) as list
if the (count of printerList) is 1 then
set thePrinter to {item 1 of printerList} as string
set theQueue to {item 1 of queueList} as string
else
tell me to activate
try
set thePrinter to (choose from list printerList with title "Printers" with prompt "Select a printer:")
end try
end if
set thePrinter to item 1 of thePrinter
set item_num to my list_position(thePrinter, printerList)
set theQueue to item item_num in queueList
on list_position(this_item, this_list)
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then return i
end repeat
return 0
end list_position
(I’ve omitted code that deals with situations where no printer exists, etc.)
This worked very well as a folder action script. But I am now converting this script to be a launch daemon, loaded via launchctl, and I cannot figure out how to get “choose from list” to display a list to the user, because a launch daemon like this cannot interact directly with the user (as I understand it).
I know that I can use “tell application ‘System Events’ display dialog” etc. to display a dialog from a launch daemon, but I can’t make “choose from list” display by that method. I’ve tried using osascript, but I can’t figure out how to get the list of printers into the command line. Is there any other way to do this with a launch daemon?
I’ve searched for an answer to this without success. Can anyone see a way to accomplish this?
Many thanks for any help.