Re: knowing if a printer is connected

2009-11-24 Thread Peter Brigham MD
Here is the debugged script. It turned out to be more complicated than  
I thought, as usual. (Murphy was a programmer, right?)


Call checkPrinter before any printing commands. The first time you  
plug in a never-encountered printer and try to print something you  
will be asked to identify the printer by selecting it in an answer  
printer dialog; thereafter that printer will be used for printing  
automatically whenever it is connected and turned on.


Note that the currently chosen default printer (in the system  
preferences) will *not* be changed, just the Rev global property the  
printerName, which contains the name of the printer the Rev engine  
will use for printing from any RevTalk commands.


This is Mac OSX only at this point. Someone with WIndows expertise  
could adapt this as needed -- might be trivial, might be complex. I  
don't know, I don't do Windows.


-- Peter

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



on checkPrinter
   put getActivePrinter() into tLivePrinterInIOR
   --##  listing of connected printer(s) in IO registry
   if tLivePrinterInIOR = empty then
  put You are not connected to any active printer. Please check  
that  \
 your printer is turned on and connected properly. into  
tPrompt

  answer tPrompt as sheet
  exit to top
   else if the number of lines of tLivePrinterInIOR  1 then
  --##  more than one connected device might be a printer
  --##  but we might know this printer already
  repeat for each line p in tLivePrinterInIOR
 put the IORtoPrinterName[p] of stack myLibrary into  
tPossiblePrinterName
 --##  myLibrary or whatever stack you use to store the  
customprop
 --##  customprop IORtoPrinterName[p] gives name of the  
(possible) printer

 --##  in system prefs, stored when printer first encountered
 --##  will return empty if p is not a known printer
  if tPossiblePrinterName  empty then
--## found a known printer, set the printername, then done
set the printername to tPossiblePrinterName
exit checkPrinter
 end if
  end repeat
  --##  no entries are a known printer,
  --##  ask user to sort it out
  --##  have to construct answer dialog
  --##  with buttons for each device
  put q(cancel) into btnList
  repeat for each line p in tLivePrinterInIOR
 put q(truncate(p,18)) into btnName
 --##  so button names are not too long
 put q(truncate(p,50)) into promptLine
 put  and   btnName after btnList
 put   crpromptLine after promptList
  end repeat
  put More than one device might be a connected printer. Please  
select the \
  printer from the following:  quote  promptList  
into theDo

  put answer  quote before theDo
  put  with  btnList  as sheet after theDo
  do theDo
  put it into whichDevice
  if whichDevice = cancel then exit to top
  if char -1 of whichDevice = …Â
 then delete char -1 of whichDevice
  --##  ellipsis character (option-;) from the truncate() function
  put line lineoffset(whichDevice,tLivePrinterInIOR) of  
tLivePrinterInIOR into \

tLivePrinterInIOR
   end if
   --##  now tLivePrinterInIOR contains one entry
   put the IORtoPrinterName[tLivePrinterInIOR] of stack myLibrary \
 into tLivePrinterName
   --##  myLibrary or whatever stack you used to store the customprop
   --##  IORtoPrinterName[tLivePrinterInIOR] gives name of this printer
   --##  in system prefs, stored when printer first encountered
   --##  it will return empty if not a known printer
   put the printername into tCurrentRevPrinterName
   --##  printer currently designated as the printer for Rev to use
   if tCurrentRevPrinterName = tLivePrinterName and  
tCurrentRevPrinterName \

 empty then
  exit checkPrinter
  --##  currently connected to the chosen printer,
  --##  do nothing further
   end if
   --##  else:
   if tLivePrinterName = empty then
  --##  never seen this printer
  put Please choose the current printer (  tLivePrinterInIOR  \
) so it can be identified in the future. into tPrompt
  answer tPrompt as sheet
  set the systemprintselector to true
  answer printer
  --##  sets the printername (used by Rev for printing)
  if the result = cancel then exit to top
  put the printername into tPrinterName
  set the IORtoPrinterName[tLivePrinterInIOR] of stack  
myLibrary to tPrinterName
  --##  myLibrary or whatever stack you use to store the  
customprop

  else
  --##  a known printer is currently live, just start using it
  set the printername to tLivePrinterName
   end if
end checkPrinter

function getActivePrinter
   put shell(ioreg) into tList
   filter tList with *class IOUSBDevice*
   filter tList without *UserClient*
   filter tList without *Keyboard*
   filter 

Re: knowing if a printer is connected

2009-11-23 Thread Peter Brigham MD
This worked for me on my home printer, and I had high hopes for it,  
but if fails this morning here at work. The problem seems to be that  
with some printers the listing from the ioreg call has little relation  
to the name of the printer. For instance, my Brother laserjet MFC 8220  
(combo printer fax copier) has an ioreg listing of:


+-o iousbcompositedev...@fd10  class IOUSBDevice, registered,  
matched, active, busy 0, retain 12


and there is no way of telling that this is a Brother 8220 or relating  
it to the availablePrinters, not on the face of it, anyway.


I'm working on a solution that will involve storing the ioreg name of  
a given printer as a customprop ioregListing[printerName] More to  
come. I'm determined to make this work as invisibly as possible. It  
has long been a irritation for me that the system doesn't  
automatically just send print jobs to the available printer. There's  
no reason on earth why you should have to change printers manually  
(after the first time you use one, of course). The system knows what's  
plugged in, for goodness sake. [g...]


-- Peter

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


On Nov 21, 2009, at 11:36 PM, Phil Davis wrote:

Everyone is doing it, so... here is what I came up with. Watch line  
wraps please. Hopefully the comments explain what the code is doing.



on mouseUp
 answer UsbPrinterList()
end mouseUp


function UsbPrinterList
 -- set item delimiter
 set the itemDelimiter to tab
  -- make a list of all active USB I/O devices
 put shell(ioreg) into tActiveDeviceList
 filter tActiveDeviceList with *IOUSBDevice* -- remove all but USB  
devices from list

 replace @ with tab in tActiveDeviceList -- isolate device name
 replace +-o with tab in tActiveDeviceList -- device name is item  
2 of each line

  -- get all known printer names, whether active or not
 put the availablePrinters into tPrinterNames
  -- identify active USB printers in the USB device list
 put empty into tUsbPrinters
 repeat for each line tDeviceLine in tActiveDeviceList
put word 1 to -1 of item 2 of tDeviceLine into tDeviceName --  
could be partial device name

get tPrinterNames
filter it with (*  tDeviceName  *)
if it = empty then next repeat -- device is not a printer
-- USB device is a printer, so get full name
repeat for each line tFoundPrinter in it
   put tFoundPrinter  cr after tUsbPrinters
end repeat
 end repeat
 delete last char of tUsbPrinters -- trailing CR
  return tUsbPrinters
end UsbPrinterList


Thanks -
Phil Davis



JosepM wrote:

Hi,

In English work, but in Spanish and others languages don't.

The result of the shell command is:
destino por omision del sistema: HP_Photosmart_C4200_series

So we must check for the : and get the printer name.

  set itemdel to :
  put item 2 of shell(lpstat -d) into tDefaultPrinter


function getDefaultPrinter
 put word 4 of shell(lpstat -d) into tDefaultPrinter
 --   shell returns:  system default destination: HP_DESKJET_845C
 replace _ with space in tDefaultPrinter
 return tDefaultPrinter
end getDefaultPrinter

The getActivePrinter get all the USB devices. In my case, my LaCie  
disk, the
iPhone, the DataTraveler and the HP printer.. How to filter between  
them?


Salut,
Josep



--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-23 Thread Phil Davis

Hi Peter,

If you filter out all lines from ioreg output except ones that contain 
IOUSBCompositeDevice, do you see the printer name in any line? If so, 
maybe available printer names could be matched to the device names in 
IOUSBDevice and IOUSBCompositeDevice records.


Phil



Peter Brigham MD wrote:
This worked for me on my home printer, and I had high hopes for it, 
but if fails this morning here at work. The problem seems to be that 
with some printers the listing from the ioreg call has little relation 
to the name of the printer. For instance, my Brother laserjet MFC 8220 
(combo printer fax copier) has an ioreg listing of:


+-o iousbcompositedev...@fd10  class IOUSBDevice, registered, 
matched, active, busy 0, retain 12


and there is no way of telling that this is a Brother 8220 or relating 
it to the availablePrinters, not on the face of it, anyway.


I'm working on a solution that will involve storing the ioreg name of 
a given printer as a customprop ioregListing[printerName] More to 
come. I'm determined to make this work as invisibly as possible. It 
has long been a irritation for me that the system doesn't 
automatically just send print jobs to the available printer. There's 
no reason on earth why you should have to change printers manually 
(after the first time you use one, of course). The system knows what's 
plugged in, for goodness sake. [g...]


-- Peter

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


On Nov 21, 2009, at 11:36 PM, Phil Davis wrote:

Everyone is doing it, so... here is what I came up with. Watch line 
wraps please. Hopefully the comments explain what the code is doing.



on mouseUp
 answer UsbPrinterList()
end mouseUp


function UsbPrinterList
 -- set item delimiter
 set the itemDelimiter to tab
  -- make a list of all active USB I/O devices
 put shell(ioreg) into tActiveDeviceList
 filter tActiveDeviceList with *IOUSBDevice* -- remove all but USB 
devices from list

 replace @ with tab in tActiveDeviceList -- isolate device name
 replace +-o with tab in tActiveDeviceList -- device name is item 2 
of each line

  -- get all known printer names, whether active or not
 put the availablePrinters into tPrinterNames
  -- identify active USB printers in the USB device list
 put empty into tUsbPrinters
 repeat for each line tDeviceLine in tActiveDeviceList
put word 1 to -1 of item 2 of tDeviceLine into tDeviceName -- 
could be partial device name

get tPrinterNames
filter it with (*  tDeviceName  *)
if it = empty then next repeat -- device is not a printer
-- USB device is a printer, so get full name
repeat for each line tFoundPrinter in it
   put tFoundPrinter  cr after tUsbPrinters
end repeat
 end repeat
 delete last char of tUsbPrinters -- trailing CR
  return tUsbPrinters
end UsbPrinterList


Thanks -
Phil Davis



JosepM wrote:

Hi,

In English work, but in Spanish and others languages don't.

The result of the shell command is:
destino por omision del sistema: HP_Photosmart_C4200_series

So we must check for the : and get the printer name.

  set itemdel to :
  put item 2 of shell(lpstat -d) into tDefaultPrinter


function getDefaultPrinter
 put word 4 of shell(lpstat -d) into tDefaultPrinter
 --   shell returns:  system default destination: HP_DESKJET_845C
 replace _ with space in tDefaultPrinter
 return tDefaultPrinter
end getDefaultPrinter

The getActivePrinter get all the USB devices. In my case, my LaCie 
disk, the
iPhone, the DataTraveler and the HP printer.. How to filter between 
them?


Salut,
Josep



--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution



--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-23 Thread Peter Brigham MD
There is only that one entry in the ioreg output that contains  
IOUSBCompositeDevice and that entry disappears if I unplug that  
printer, so it's undoubtedly the listing for my laserjet. But there is  
nothing in the ioreg listing that identifies the printer more  
specifically, and thus there is no way of linking that entry to the  
listing in my available printers just by looking at the names. (Not to  
mention that the user can rename any printer in the system prefs  
printer list to whatever s/he likes.)


I think I have found a solution that involves storing the printername  
as the value of a customprop with key = the ioreg name -- do this the  
first time the printer is encountered then use the customprop to set  
the printername automatically after that. I'm testing it over the next  
few days -- seems to be working so far -- and I will post the working  
script (I hope) in a little while.


-- Peter

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


On Nov 23, 2009, at 4:40 PM, Phil Davis wrote:


Hi Peter,

If you filter out all lines from ioreg output except ones that  
contain IOUSBCompositeDevice, do you see the printer name in any  
line? If so, maybe available printer names could be matched to the  
device names in IOUSBDevice and IOUSBCompositeDevice records.


Phil



Peter Brigham MD wrote:
This worked for me on my home printer, and I had high hopes for it,  
but if fails this morning here at work. The problem seems to be  
that with some printers the listing from the ioreg call has little  
relation to the name of the printer. For instance, my Brother  
laserjet MFC 8220 (combo printer fax copier) has an ioreg listing of:


+-o iousbcompositedev...@fd10  class IOUSBDevice, registered,  
matched, active, busy 0, retain 12


and there is no way of telling that this is a Brother 8220 or  
relating it to the availablePrinters, not on the face of it, anyway.


I'm working on a solution that will involve storing the ioreg name  
of a given printer as a customprop ioregListing[printerName] More  
to come. I'm determined to make this work as invisibly as possible.  
It has long been a irritation for me that the system doesn't  
automatically just send print jobs to the available printer.  
There's no reason on earth why you should have to change printers  
manually (after the first time you use one, of course). The system  
knows what's plugged in, for goodness sake. [g...]


-- Peter

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


On Nov 21, 2009, at 11:36 PM, Phil Davis wrote:

Everyone is doing it, so... here is what I came up with. Watch  
line wraps please. Hopefully the comments explain what the code is  
doing.



on mouseUp
answer UsbPrinterList()
end mouseUp


function UsbPrinterList
-- set item delimiter
set the itemDelimiter to tab
 -- make a list of all active USB I/O devices
put shell(ioreg) into tActiveDeviceList
filter tActiveDeviceList with *IOUSBDevice* -- remove all but  
USB devices from list

replace @ with tab in tActiveDeviceList -- isolate device name
replace +-o with tab in tActiveDeviceList -- device name is item  
2 of each line

 -- get all known printer names, whether active or not
put the availablePrinters into tPrinterNames
 -- identify active USB printers in the USB device list
put empty into tUsbPrinters
repeat for each line tDeviceLine in tActiveDeviceList
   put word 1 to -1 of item 2 of tDeviceLine into tDeviceName --  
could be partial device name

   get tPrinterNames
   filter it with (*  tDeviceName  *)
   if it = empty then next repeat -- device is not a printer
   -- USB device is a printer, so get full name
   repeat for each line tFoundPrinter in it
  put tFoundPrinter  cr after tUsbPrinters
   end repeat
end repeat
delete last char of tUsbPrinters -- trailing CR
 return tUsbPrinters
end UsbPrinterList


Thanks -
Phil Davis



JosepM wrote:

Hi,

In English work, but in Spanish and others languages don't.

The result of the shell command is:
destino por omision del sistema: HP_Photosmart_C4200_series

So we must check for the : and get the printer name.

 set itemdel to :
 put item 2 of shell(lpstat -d) into tDefaultPrinter


function getDefaultPrinter
put word 4 of shell(lpstat -d) into tDefaultPrinter
--   shell returns:  system default destination: HP_DESKJET_845C
replace _ with space in tDefaultPrinter
return tDefaultPrinter
end getDefaultPrinter

The getActivePrinter get all the USB devices. In my case, my  
LaCie disk, the
iPhone, the DataTraveler and the HP printer.. How to filter  
between them?


Salut,
Josep



--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution



Re: knowing if a printer is connected

2009-11-21 Thread Peter Brigham MD
 Davis

PDS Labs
Professional Software Development
http://pdslabs.net

___
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


View message @ 
http://n4.nabble.com/knowing-if-a-printer-is-connected-tp624188p624409.html
To unsubscribe from Re: knowing if a printer is connected, click  
here.





--
View this message in context: 
http://n4.nabble.com/knowing-if-a-printer-is-connected-tp624188p624552.html
Sent from the Revolution - User mailing list archive at Nabble.com.
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-21 Thread JosepM

Hi,

In English work, but in Spanish and others languages don't.

The result of the shell command is:
destino por omision del sistema: HP_Photosmart_C4200_series

So we must check for the : and get the printer name.

   set itemdel to :
   put item 2 of shell(lpstat -d) into tDefaultPrinter


function getDefaultPrinter
  put word 4 of shell(lpstat -d) into tDefaultPrinter
  --   shell returns:  system default destination: HP_DESKJET_845C
  replace _ with space in tDefaultPrinter
  return tDefaultPrinter
end getDefaultPrinter

The getActivePrinter get all the USB devices. In my case, my LaCie disk, the
iPhone, the DataTraveler and the HP printer.. How to filter between them?

Salut,
Josep
-- 
View this message in context: 
http://n4.nabble.com/knowing-if-a-printer-is-connected-tp624188p699883.html
Sent from the Revolution - User mailing list archive at Nabble.com.
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-21 Thread Phil Davis
Everyone is doing it, so... here is what I came up with. Watch line 
wraps please. Hopefully the comments explain what the code is doing.



on mouseUp
  answer UsbPrinterList()
end mouseUp


function UsbPrinterList
  -- set item delimiter
  set the itemDelimiter to tab
 
  -- make a list of all active USB I/O devices

  put shell(ioreg) into tActiveDeviceList
  filter tActiveDeviceList with *IOUSBDevice* -- remove all but USB 
devices from list

  replace @ with tab in tActiveDeviceList -- isolate device name
  replace +-o with tab in tActiveDeviceList -- device name is item 2 
of each line
 
  -- get all known printer names, whether active or not

  put the availablePrinters into tPrinterNames
 
  -- identify active USB printers in the USB device list

  put empty into tUsbPrinters
  repeat for each line tDeviceLine in tActiveDeviceList
 put word 1 to -1 of item 2 of tDeviceLine into tDeviceName -- 
could be partial device name

 get tPrinterNames
 filter it with (*  tDeviceName  *)
 if it = empty then next repeat -- device is not a printer

 -- USB device is a printer, so get full name

 repeat for each line tFoundPrinter in it
put tFoundPrinter  cr after tUsbPrinters
 end repeat
  end repeat
  delete last char of tUsbPrinters -- trailing CR
 
  return tUsbPrinters

end UsbPrinterList


Thanks -
Phil Davis



JosepM wrote:

Hi,

In English work, but in Spanish and others languages don't.

The result of the shell command is:
destino por omision del sistema: HP_Photosmart_C4200_series

So we must check for the : and get the printer name.

   set itemdel to :
   put item 2 of shell(lpstat -d) into tDefaultPrinter


function getDefaultPrinter
  put word 4 of shell(lpstat -d) into tDefaultPrinter
  --   shell returns:  system default destination: HP_DESKJET_845C
  replace _ with space in tDefaultPrinter
  return tDefaultPrinter
end getDefaultPrinter

The getActivePrinter get all the USB devices. In my case, my LaCie disk, the
iPhone, the DataTraveler and the HP printer.. How to filter between them?

Salut,
Josep
  


--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-20 Thread JosepM

I'm very glad that this will be usefully for you. As I say, the only  
problem is convert the printer name to use _. I preparing my own  
stack printer options to print using the shell commands.

Here you can found more info with more deep.

http://www.cups.org/doc-1.1/sum.html

When I have something visible I send you for if can be usefully.


Salut,
Josep

El 20/11/2009, a las 6:14, Phil Davis-5 [via Runtime Revolution]  
escribió:

 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
 [hidden email]
 Please visit this url to subscribe, unsubscribe and manage your  
 subscription preferences:
 http://lists.runrev.com/mailman/listinfo/use-revolution


 View message @ 
 http://n4.nabble.com/knowing-if-a-printer-is-connected-tp624188p624409.html
 To unsubscribe from Re: knowing if a printer is connected, click here.



-- 
View this message in context: 
http://n4.nabble.com/knowing-if-a-printer-is-connected-tp624188p624552.html
Sent from the Revolution - User mailing list archive at Nabble.com.
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-20 Thread Peter Brigham MD
Yeah, I discovered that one already. Many different ways of getting  
the printers that are in the system preferences printing panel. But  
apparently no way of telling which one is actually connected and  
live. It's hard to believe that the system is unaware of this piece  
of info until a print job is actually sent to the driver. I keep  
thinking there must be a way, via a shell function at the very least.  
But maybe not Any other ideas before I give up on this?


-- Peter

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


On Nov 19, 2009, at 7:10 PM, Phil Davis wrote:


BNig wrote:
The last item of the properties of a printer is the status, it  
unfortunately

returns idle. At least you get the names of the printers. The current
printer is the default printer.
regards
Bernd




You can also get the names of the printers with:

 put the availablePrinters into tList

:-)
--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-20 Thread Peter Brigham MD

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 8...@1d10  class IOUSBDevice, \
   -- registered, matched, active, busy 0, retain 8
   --  | |   |   +-o IR recei...@5d10  class IOUSBDevice, \
   -- registered, matched, active, busy 0, retain 8
   --  | |   |   +-o Apple Internal Keyboard / track...@5d20   
class \
   -- IOUSBDevice, registered, matched, active, busy 0,  
retain 10

   --  | |   |   +-o iousbwirelesscontrollerdev...@1a10  class \
   -- IOUSBDevice, registered, matched, active, busy 0,  
retain 10

   --  | |   |   +-o wireless laser notebook mo...@1a20  class \
   -- IOUSBDevice, registered, matched, active, busy 0,  
retain 8

   --  | |   |   +-o Built-in isi...@fd40  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
pmb...@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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-19 Thread BNig

Peter,

tell application Printer Setup Utility
set Current_Printer to name of current printer -- set a variable for 
the
name of your current/default printer
end tell

this applescript tells me the currently selected printer on MacOSX 10.5.8

regards
Bernd


Peter Brigham MD wrote:
 
 I have a stack system that is being used on laptops (at this point Mac  
 OSX only). One of my beta testers uses it in three different  
 locations. Among many other things, the stack prints out notes and  
 various other text files from within Rev (running in IDE on RevMedia  
 4.0 -- eventually I'll get to porting it as a standalone). As it  
 stands now, the user needs to select the currently available printer  
 using the system preferences. I need a way to discover if the printer  
 designated as active in the system preferences is actually the one  
 that is plugged into the USB port. I have a way for the user to change  
 the printer from within the stack, but I'd like to avoid the situation  
 where he tries to print something and gets the bobbing printer driver  
 icon in the dock telling him that that printer is unavailable (because  
 he's at a different site and forgot to change his printer designation).
 
 The ideal solution would be to be able to detect the currently  
 connected printer and send any print job automatically  to that  
 printer, but I'd settle for just being able to post an alert when  
 trying to print to notify him that he is about to use an unavailable  
 printer. How do I detect what printer is connected? Or at least,  
 detect if a designated printer is connected or not?
 
 -- Peter
 
 Peter M. Brigham
 pmb...@gmail.com
 http://home.comcast.net/~pmbrig
 

-- 
View this message in context: 
http://n4.nabble.com/knowing-if-a-printer-is-connected-tp624188p624194.html
Sent from the Revolution - User mailing list archive at Nabble.com.
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-19 Thread BNig

Peter,
I was a little too fast with my reply, I am afraid

this gives me all the information of the current printer unfortunately it
does return idle even if the current printer is off.

tell application Printer Setup Utility
set Current_Printer to name of current printer -- set a variable for 
the
name of your current/default printer
set tKind to kind of current printer
set tproperties to properties of current printer
set tJob to job of current printer
end tell

Since you are looking for an active/connected printer this is probably not
working. 
regards
Bernd




BNig wrote:
 
 Peter,
 
 tell application Printer Setup Utility
   set Current_Printer to name of current printer -- set a variable for 
 the
 name of your current/default printer
 end tell
 
 this applescript tells me the currently selected printer on MacOSX 10.5.8
 
 regards
 Bernd
 
 
 Peter Brigham MD wrote:
 
 I have a stack system that is being used on laptops (at this point Mac  
 OSX only). One of my beta testers uses it in three different  
 locations. Among many other things, the stack prints out notes and  
 various other text files from within Rev (running in IDE on RevMedia  
 4.0 -- eventually I'll get to porting it as a standalone). As it  
 stands now, the user needs to select the currently available printer  
 using the system preferences. I need a way to discover if the printer  
 designated as active in the system preferences is actually the one  
 that is plugged into the USB port. I have a way for the user to change  
 the printer from within the stack, but I'd like to avoid the situation  
 where he tries to print something and gets the bobbing printer driver  
 icon in the dock telling him that that printer is unavailable (because  
 he's at a different site and forgot to change his printer designation).
 
 The ideal solution would be to be able to detect the currently  
 connected printer and send any print job automatically  to that  
 printer, but I'd settle for just being able to post an alert when  
 trying to print to notify him that he is about to use an unavailable  
 printer. How do I detect what printer is connected? Or at least,  
 detect if a designated printer is connected or not?
 
 -- Peter
 
 Peter M. Brigham
 pmb...@gmail.com
 http://home.comcast.net/~pmbrig
 
 
 

-- 
View this message in context: 
http://n4.nabble.com/knowing-if-a-printer-is-connected-tp624188p624225.html
Sent from the Revolution - User mailing list archive at Nabble.com.
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-19 Thread Peter Brigham MD
It returns idle in all cases? Are you saying that it doesn't  
distinguish if the printer is on/connected vs off/disconnected?


How would I get the contents of the various printer properties from  
this script into rev variables to test this out? Do I use an 'on  
appleEvent' handler -- if so, how? Sorry for the naive questions, but  
I haven't used applescript much.


-- Peter

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


On Nov 19, 2009, at 3:33 PM, BNig wrote:



Peter,
I was a little too fast with my reply, I am afraid

this gives me all the information of the current printer  
unfortunately it

does return idle even if the current printer is off.

tell application Printer Setup Utility
	set Current_Printer to name of current printer -- set a variable  
for the

name of your current/default printer
set tKind to kind of current printer
set tproperties to properties of current printer
set tJob to job of current printer
end tell

Since you are looking for an active/connected printer this is  
probably not

working.
regards
Bernd




BNig wrote:


Peter,

tell application Printer Setup Utility
	set Current_Printer to name of current printer -- set a variable  
for the

name of your current/default printer
end tell

this applescript tells me the currently selected printer on MacOSX  
10.5.8


regards
Bernd


Peter Brigham MD wrote:


I have a stack system that is being used on laptops (at this point  
Mac

OSX only). One of my beta testers uses it in three different
locations. Among many other things, the stack prints out notes and
various other text files from within Rev (running in IDE on RevMedia
4.0 -- eventually I'll get to porting it as a standalone). As it
stands now, the user needs to select the currently available printer
using the system preferences. I need a way to discover if the  
printer

designated as active in the system preferences is actually the one
that is plugged into the USB port. I have a way for the user to  
change
the printer from within the stack, but I'd like to avoid the  
situation
where he tries to print something and gets the bobbing printer  
driver
icon in the dock telling him that that printer is unavailable  
(because
he's at a different site and forgot to change his printer  
designation).


The ideal solution would be to be able to detect the currently
connected printer and send any print job automatically  to that
printer, but I'd settle for just being able to post an alert when
trying to print to notify him that he is about to use an unavailable
printer. How do I detect what printer is connected? Or at least,
detect if a designated printer is connected or not?

-- Peter

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






--
View this message in context: 
http://n4.nabble.com/knowing-if-a-printer-is-connected-tp624188p624225.html
Sent from the Revolution - User mailing list archive at Nabble.com.
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your  
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-19 Thread BNig

Peter,

to test this put this applescript into a field 1 and have a field 2 for the
result

-
tell application Printer Setup Utility
set tReturn to 
set x to name of every printer as list
repeat with i from 1 to count of items of x
set tReturn to tReturn  item i of x  tab
set tReturn to tReturn  item -1 of (properties of printer 
(item i of x)
as list)  linefeed
end repeat
return tReturn
end tell


put this into a button
--
on mouseUp
   do field 1 as applescript
   put char 2 to - 3 of  the result into field 2 -- gets rid of quotes and
trailing linefeed
end mouseUp

so basically you let applescript return the value/s you are interested in
and you check the result.
The last item of the properties of a printer is the status, it unfortunately
returns idle. At least you get the names of the printers. The current
printer is the default printer.
regards
Bernd



Peter Brigham MD wrote:
 
 It returns idle in all cases? Are you saying that it doesn't  
 distinguish if the printer is on/connected vs off/disconnected?
 
 How would I get the contents of the various printer properties from  
 this script into rev variables to test this out? Do I use an 'on  
 appleEvent' handler -- if so, how? Sorry for the naive questions, but  
 I haven't used applescript much.
 
 -- Peter
 
 Peter M. Brigham
 pmb...@gmail.com
 http://home.comcast.net/~pmbrig
 

-- 
View this message in context: 
http://n4.nabble.com/knowing-if-a-printer-is-connected-tp624188p624321.html
Sent from the Revolution - User mailing list archive at Nabble.com.
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-19 Thread Phil Davis

Hi Peter,

Here is another approach for OS X that might give you info that's easier 
to use. Or not.


put shell(system_profiler SPPrintersDataType) into tDescriptions

In my world it returns this:
--- start of data ---
Printers:

   Canon iP1700:

 Status: Idle
 Print Server: Local
 Driver Version: 5.8.3
 Default: No
 URI: usb://Canon/iP1700?serial=705357
 PPD: Canon iP1700
 PPD File Version: 1.0
 PostScript Version: (3011.104) 0

   HP Color LaserJet 2600n:

 Status: Idle
 Print Server: Local
 Driver Version: 1.3.0501
 Default: Yes
 URI: 
mdns://HP%20Color%20LaserJet%202600n._pdl-datastream._tcp.local./?bidi

 PPD: HP Color LaserJet 2600n
 PPD File Version: 1.0
 PostScript Version: (3011.104) 0

   Officejet Pro 8500 A909g [7134F4]:

 Status: Idle
 Print Server: Local
 Driver Version: 1.2
 Default: No
 URI: 
mdns://Officejet%20Pro%208500%20A909g%20%5B7134F4%5D._pdl-datastream._tcp.local./?bidi

 PPD: HP Officejet Pro 8500 A909g Series
 PPD File Version: 1.2
 PostScript Version: (3011.104) 0

--- end of data ---

I see the URI line in each description tells if it is USB or not. BUT it 
doesn't tell you the status of the printers; I got the same descriptions 
when my USB printer was turned on/turned off/unplugged.


If I learn more I'll post it.

Phil Davis



Peter Brigham MD wrote:
It returns idle in all cases? Are you saying that it doesn't 
distinguish if the printer is on/connected vs off/disconnected?


How would I get the contents of the various printer properties from 
this script into rev variables to test this out? Do I use an 'on 
appleEvent' handler -- if so, how? Sorry for the naive questions, but 
I haven't used applescript much.


-- Peter

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


On Nov 19, 2009, at 3:33 PM, BNig wrote:



Peter,
I was a little too fast with my reply, I am afraid

this gives me all the information of the current printer 
unfortunately it

does return idle even if the current printer is off.

tell application Printer Setup Utility
set Current_Printer to name of current printer -- set a variable 
for the

name of your current/default printer
set tKind to kind of current printer
set tproperties to properties of current printer
set tJob to job of current printer
end tell

Since you are looking for an active/connected printer this is 
probably not

working.
regards
Bernd




BNig wrote:


Peter,

tell application Printer Setup Utility
set Current_Printer to name of current printer -- set a 
variable for the

name of your current/default printer
end tell

this applescript tells me the currently selected printer on MacOSX 
10.5.8


regards
Bernd


Peter Brigham MD wrote:


I have a stack system that is being used on laptops (at this point Mac
OSX only). One of my beta testers uses it in three different
locations. Among many other things, the stack prints out notes and
various other text files from within Rev (running in IDE on RevMedia
4.0 -- eventually I'll get to porting it as a standalone). As it
stands now, the user needs to select the currently available printer
using the system preferences. I need a way to discover if the printer
designated as active in the system preferences is actually the one
that is plugged into the USB port. I have a way for the user to change
the printer from within the stack, but I'd like to avoid the situation
where he tries to print something and gets the bobbing printer driver
icon in the dock telling him that that printer is unavailable (because
he's at a different site and forgot to change his printer 
designation).


The ideal solution would be to be able to detect the currently
connected printer and send any print job automatically  to that
printer, but I'd settle for just being able to post an alert when
trying to print to notify him that he is about to use an unavailable
printer. How do I detect what printer is connected? Or at least,
detect if a designated printer is connected or not?

-- Peter

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






--
View this message in context: 
http://n4.nabble.com/knowing-if-a-printer-is-connected-tp624188p624225.html 


Sent from the Revolution - User mailing list archive at Nabble.com.
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution


___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your 
subscription preferences:

http://lists.runrev.com/mailman/listinfo/use-revolution



--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net

___
use-revolution mailing 

Re: knowing if a printer is connected

2009-11-19 Thread Phil Davis

BNig wrote:

The last item of the properties of a printer is the status, it unfortunately
returns idle. At least you get the names of the printers. The current
printer is the default printer.
regards
Bernd

  


You can also get the names of the printers with:

  put the availablePrinters into tList

:-)
--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-19 Thread Phil Davis
Here's another OS X shell command that will list only the USB printers 
turned on. Unfortunately, it doesn't list them by their full names.


Here's the code (in a button):

on mouseUp
  put shell(ioreg) into tList
  filter tList with *IOUSBDevice*
  put the number of lines in tList  cr  tList into fld list2
end mouseUp


Here's the output on my machine:
8
   | |   |   +-o IR recei...@450  class IOUSBDevice, registered, 
matched, active, busy 0, retain 8
   | |   |   +-o Apple Cinema disp...@2432  class IOUSBDevice, 
registered, matched, active, busy 0, retain 8
   | |   |   +-o C-Media USB Audio   @2433  class IOUSBDevice, 
registered, matched, active, busy 0, retain 9
   | |   |   +-o Apple Cinema disp...@2472  class IOUSBDevice, 
registered, matched, active, busy 0, retain 8
   | |   |   +-o ip1...@2431  class IOUSBDevice, registered, 
matched, active, busy 0, retain 8
   | |   |   +-o Microsoft 3-Button Mouse with IntelliEye(TM)@640  
class IOUSBDevice, registered, matched, active, busy 0, retain 8
   | |   |   +-o Bluetooth USB Host control...@611  class 
IOUSBDevice, registered, matched, active, busy 0, retain 11
   | |   |   +-o Apple keybo...@2622  class IOUSBDevice, 
registered, matched, active, busy 0, retain 9


Line 5 above is the USB printer.
When I turn the printer off and run the code again, I get 7 lines and 
the printer line is missing.


This printer shows up in the availablePrinters list as Canon iP1700. 
So there's a partial association between the 2 sets of data.


FWIW -
Phil



Phil Davis wrote:

BNig wrote:
The last item of the properties of a printer is the status, it 
unfortunately

returns idle. At least you get the names of the printers. The current
printer is the default printer.
regards
Bernd

  


You can also get the names of the printers with:

  put the availablePrinters into tList

:-)


--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-19 Thread JosepM

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
-- 
View this message in context: 
http://n4.nabble.com/knowing-if-a-printer-is-connected-tp624188p624396.html
Sent from the Revolution - User mailing list archive at Nabble.com.
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: knowing if a printer is connected

2009-11-19 Thread Phil Davis

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@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution