I'm trying to create a LaunchDaemon that runs a script when a USB-C or Thunderbolt dock is connected. I've found several solutions to run a script when a specific device is connected. But I need a solution that runs a script when any dock is connected.
As virtually all docks include a USB Hub, I tried to identify those and include them in a LauchDeamon: No luck. Then I looked into just triggering a script on any USB device like this:
<key>LaunchEvents</key>
<dict>
<key>com.apple.iokit.matching</key>
<dict>
<key>com.apple.device-attach</key>
<dict>
<key>IOProviderClass</key>
<string>IOUSBHostDevice</string>
<key>IOMatchLaunchStream</key>
<true/>
<key>IOMatchStream</key>
<true/>
</dict>
</dict>
</dict>
(Not the complete files)
Basically the same approach I've found for specific devices, but removing the device identifiers. Also no luck.
I've found EventScript. This application can run a script when a USB device is attached. But I prefer a solution that leverages macOS built-in tools/capabilities.