Skip to content

Instantly share code, notes, and snippets.

@rmanly
Created October 25, 2012 17:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmanly/3954329 to your computer and use it in GitHub Desktop.
Save rmanly/3954329 to your computer and use it in GitHub Desktop.
ARD login to lab with different accounts
#!/bin/bash
computer_name=$(scutil --get ComputerName)
login() {
/usr/bin/osascript << EOF
tell application "System Events"
keystroke "${1}"
keystroke return
delay 1
keystroke "${2}"
keystroke return
end tell
EOF
}
# just add more case statements as needed with the
# computername as the choice and the username and password
case "${computer_name}" in
lab_imac-01)
login user1 "pass1"
;;
lab_imac-02)
login user2 "pass2"
;;
*)
echo "ERROR: computername not found in case!"
exit 1
;;
esac
@gchristian
Copy link

This works - it expands the bash variables in the script before executing it. And allows you to basically embed the script itself instead of piece it together with multiple lines or multiple -e arguments to osascript.

login() {

exec osascript <<EOF

tell application "System Events"
keystroke "${1}"
keystroke return
delay 1
keystroke "${2}"
keystroke return
end tell
EOF
}

@rmanly
Copy link
Author

rmanly commented Oct 25, 2012

Of course! I have done this before myself when passing a variable from a bash script to an AppleScript Window!

Well done. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment