Ever since I registered my YubiKey with my Mac, I wanted to have one feature: Whenever I unplug it at work, I want the device to be locked. Therefore, I looked at implementations like yubiswitch but for one reason or another I decided to solve this little problem by myself.
At first I wanted to give Swift a try and found some functionality inside IOKit that might help me detect when a certain USB device got disconnected. Sadly, I don’t have enough time do learn Swift + Foundation + IOKit right now. So I’ve decided to go with the duct tape approach at this point:
- A simple shell script that checks the connected USB devices for one named
Yubikey
and if it first found one and all of a sudden not anymore, it triggers macOS to launch the screensaver. - And a LaunchAgent to launch that script once the user logs in.
You can find the current implementation here. I really don’t like this approach but I simply don’t have the time for something involving OS-level notifications right now. I still want to do it the proper way, though, some time in the future π
Do you want to give me feedback about this article in private? Please send it to comments@zerokspot.com.
Alternatively, this website also supports Webmentions. If you write a post on a blog that supports this technique, I should get notified about your link π