Execute an application on Mac OS X when a particular type of USB device is connected?

前端 未结 5 2253
感动是毒
感动是毒 2020-12-14 03:32

I need to implement a Mac OS X application. In my application I need to do two things:

  1. Execute / Open an application when a particular type of USB device is c
5条回答
  •  旧巷少年郎
    2020-12-14 03:59

    You can use launchd. Try man launchd and man launchd.plist.

    It seems that launchd can work with USB events, even though this feature is poorly documented. I found it on: man xpc_set_event_stream_handler

    Here's an example. If you put the following into: ~/Library/LaunchAgents/com.example.plist, your program should start when a USB device is connected.

    
    
    
    
        Label
        com.example.program
        ProgramArguments
        
        /path/to/program
        
        LaunchEvents
        
                com.apple.iokit.matching
                
                        com.apple.device-attach
                        
                                idProduct
                                1234
                                idVendor
                                1337
                                IOProviderClass
                                IOUSBDevice
                                IOMatchLaunchStream
                                
                        
                
        
    
    
    

提交回复
热议问题