some time ago I made a simple solution for the OS X locking and locking with yubikey and I made it available on github at https://github.com/shtirlic/yubikeylockd
, I am using it for a while and it works good for me.
git clone https://github.com/shtirlic/yubikeylockd.git
cd yubikeylockd && make all
How it works
When you attach Yubikey for the first time launchctl will run yubikeylockd daemon
that will simply monitor the state of the given USB device.
Daemon based on the sample provided by Apple for IOKit development.
It does two things:
- when device is attached it makes activity via IOPMAssertionDeclareUserActivity call to turn screen on
- after device is detached it uses IORequestIdle to put display to sleep and (if you configured it) also lock the OS X