knowing if a printer is connected

Peter Brigham MD pmbrig at gmail.com
Fri Nov 20 11:07:42 EST 2009


This seems to do it for me as well. I'm trying this (watch linewraps)

(in a button, for testing)

on mouseUp
    put shell("ioreg") into tList
    filter tList with "*IOUSBDevice*"
    --  | |   |   +-o DeskJet 845C at 1d100000  <class IOUSBDevice, \
    --             registered, matched, active, busy 0, retain 8>
    --  | |   |   +-o IR Receiver at 5d100000  <class IOUSBDevice, \
    --             registered, matched, active, busy 0, retain 8>
    --  | |   |   +-o Apple Internal Keyboard / Trackpad at 5d200000   
<class \
    --             IOUSBDevice, registered, matched, active, busy 0,  
retain 10>
    --  | |   |   +-o IOUSBWirelessControllerDevice at 1a100000  <class \
    --             IOUSBDevice, registered, matched, active, busy 0,  
retain 10>
    --  | |   |   +-o wireless laser notebook mouse at 1a200000  <class \
    --             IOUSBDevice, registered, matched, active, busy 0,  
retain 8>
    --  | |   |   +-o Built-in iSight at fd400000  <class IOUSBDevice, \
    --             registered, matched, active, busy 0, retain 9>
    filter tList without "*Keyboard*"
    filter tList without "* IR *"
    filter tList without "*Wireless*"
    filter tList without "*mouse*"
    filter tList without "*iSight*"
    --  ?? other things to filter out to leave only printers ??
    repeat for each line d in tList
       put offset("+-o",d)+4 into startChar
       put offset("<class",d)-1 into endChar
       put sr(char startChar to endChar of d) into d2
       put offset("@",d2) into aChar
       put char 1 to aChar-1 of d2 & cr after newList
    end repeat
    delete char -1 of newList
    put newList
end mouseUp

At my site this morning, this returns "Deskjet 845C" when the printer  
is plugged in, and empty if is isn't. What else should be filtered out  
to leave only the name of the connected printer? There are probably  
other USB devices that wouldn't be caught by what I have so far. I'll  
have my beta testers' feedback to work with, but anyone else with a  
Mac who can chime in here is welcome....

... and, anyone know the significance of the number after the @  
character for each device? Could I use this to catch printers as  
opposed to other devices?

TIA,
-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig




On Nov 20, 2009, at 12:14 AM, Phil Davis wrote:

> This is the best so far!
>
> Phil Davis
>
>
>
> JosepM wrote:
>> Hi,
>>
>> Also you can use from the shell:
>>
>> lpstat -p --> to see the available printers
>> lpstat -d --> to know the default printer name
>>
>> and to send directly to the printer:
>>
>> lpr -P <name of the printer> -o page-ranges=1 -o landscape <path to  
>> the file
>> to print>
>>
>> If you check the lpr command in CUPS manual you can see a lot of  
>> options to
>> control the job sended to the printer. The question is capture the  
>> name of
>> the printer or class. The name use "_" for spaces, assigning the  
>> name directly don't work, almost
>> for me.
>>
>>
>> Salut,
>> Josep
>>
>
> -- 
> Phil Davis
>
> PDS Labs
> Professional Software Development
> http://pdslabs.net
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list