Last active
August 10, 2016 13:03
-
-
Save davedelong/56a973b142785c434335eddb99cc2b54 to your computer and use it in GitHub Desktop.
Programmatically switch to another user
This file contains hidden or 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
#!/bin/bash | |
# A script to automatically switch to another user in macOS | |
# Invoke like this: `autologin.sh {user} {password}` | |
uid=`id -u $1` | |
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID "$uid" | |
osascript <<EOD | |
-- wait for the system UI to come up | |
delay 2 | |
tell application "System Events" | |
-- type the password | |
keystroke "$2" | |
delay 1 | |
-- press enter | |
key code 36 | |
end tell | |
EOD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment