mac-device-connect-daemon icon indicating copy to clipboard operation
mac-device-connect-daemon copied to clipboard

What about detaching?

Open deg0nz opened this issue 7 years ago • 5 comments

Hi,

first of all: Thanks for this really helpful piece of code and the tutorial! It works like a charm.

I use it to trigger a script when my docking station is connected. The script I'm triggering turns off WiFi, activates another sound output device and other stuff like this..

Now, I'd like to trigger a script that reverses all these things when I disconnect the Mac from the docking station.

After searching the net for some hours now I can't find an event key that triggers on detaching. I tried to use com.apple.device-detach and com.apple.device-remove but they don't seem to work...

Do you have any idea how this could be achieved?

Thanks and greetings Beh

deg0nz avatar Oct 23 '18 21:10 deg0nz

Hi,

glad you could make use of the script! Unfortunately, I have no idea on how apple called that event, if a handler even exists. Their documentation is quite lacking in that regard ...

Good luck and best regards

himbeles avatar Oct 24 '18 06:10 himbeles

I have found this discussion on apple forums mentioning the handling of disconnects on an abstract level. https://forums.developer.apple.com/thread/108927#332600

himbeles avatar Oct 24 '18 06:10 himbeles

Hi -- I have the same problem as deg0nz unfortunately my understanding of macOS inner-workings is a bit limited. Its not clear to me how the information in the link above can be applied to solve the issue.

i don't know anything about IOMatchLaunchServiceID or any I/O registry entry, or how it relates to this.

My initial understanding was that the script would terminate when the conditions (in this case, disconnected dock) are no longer met, but after testing, i have determined that to be wrong.

Could you please elaborate on how to solve this issue?

mattftw avatar Feb 23 '22 09:02 mattftw

Looking for that as well, trying to change Keyboard layouts when plugging in my external USB keyboard, and changing back when unplugging.

If anyone found a solution, please let us know :-)

tommyknows avatar Jun 01 '22 15:06 tommyknows

Please check out my app "Stecker". In addition to device attachment, the app can also detect device detachment. It triggers the execution of selected Shortcuts from the macOS Shortcuts App. The app is very lightweight and also only acts on IOKit notifications. In contrast to the launchd approach, the direct use of the IOKit framework permits to filter for additional types of com.apple.iokit.matching events, such as device detachment. I have not found a way to filter for that type of event in launchd plists.

himbeles avatar May 07 '23 19:05 himbeles