Notification for printer getting added

  • Hello,

    I am trying to write a small app that has a button which launches the Print
    Center, and another button that gets enabled or disabled depending on
    whether a specific type of printer is in the Print Center.

    I have a notification subscription to the NSDistributedNotificationCenter
    that disables my button when this specific printer is removed from the Print

    [[NSDistributedNotificationCenter defaultCenter]
        addObserver:self selector:@selector(updatePrintTestButton:)
        name:(NSString *)kCMDeviceUnregisteredNotification

    This works perfectly.  I see the notification get triggered when a printer
    is removed from the print center, and my app disables the button as I want
    it to.

    I thought I could subscribe to the CMDeviceRegisteredNotification to see
    when a new printer is added, then check the [NSPrinters printerTypes] array
    to test for the printer I want and then enable my button.  I get the
    notification, but it seems to trigger before the printer actually shows up
    in the [NSPrinters printerTypes] array.  Because the notification seems to
    be sent before the printer is added to the array of available printers, my
    app button does not get properly enabled.  I tried to look at what other
    notifications get posted to the Distributed Notification Center and the only
    one that seems to work for my needs is subscribing to notification.

    This seems to work because every time I add a printer to my computer via
    Print Center on 10.3.3, it makes that printer the default printer.

    Does anyone know if all OS X from 10.1.5 up to Panther send this
    notification every time a printer is manually added to the computer via
    Print Center / Printer Setup Utility?  Or is there a better way to get
    triggered when a printer is added to the computer via the Print Center?

    Thanks for any suggestions.

    Trever Wilhelm
    cocoa-dev mailing list | <cocoa-dev...>
    Do not post admin requests to the list. They will be ignored.
previous month april 2004 next month
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today