Created
October 14, 2015 17:38
-
-
Save thegiantbeast/8b0caadef07347bd904f to your computer and use it in GitHub Desktop.
Yubikey presence detection and logout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Based on: http://macscripter.net/viewtopic.php?pid=149887#p149887 | |
1. Replace <your_id_vendor_here> and <your_id_product_here> with the respective id's. | |
2. When saving the file on Script Editor as AppleScript application, check the option 'Stay open'. | |
3. Add the application to your login items. | |
4. Logout & login. | |
Note: This logic works better when Challenge-Response is used for login, since the key | |
needs already to be inserted. | |
*) | |
property status : false | |
property idVendor : <your_id_vendor_here> | |
property idProduct : <your_id_product_here> | |
on YubiKeyIsConnected() | |
set grepItems to "\"idVendor\" = " & idVendor & "\\|" & "\"idProduct\" = " & idProduct | |
try | |
set theResult to paragraphs of (do shell script "ioreg -c IOUSBDevice | grep " & quoted form of grepItems) | |
return (count theResult) = 2 | |
on error | |
return false | |
end try | |
end YubiKeyIsConnected | |
on idle | |
set currentState to YubiKeyIsConnected() | |
if currentState is true and status is false then | |
set status to true | |
else if currentState is false and status is true then | |
set status to false | |
activate application "ScreenSaverEngine" | |
end if | |
return 1 | |
end idle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment