Skip to content

Instantly share code, notes, and snippets.

@mikew
Created October 2, 2009 01:00
Show Gist options
  • Save mikew/199359 to your computer and use it in GitHub Desktop.
Save mikew/199359 to your computer and use it in GitHub Desktop.
Helper scripts to send applescript key codes from terminal input
#!/bin/sh
osascript - <<EOF
tell application "System Events"
key code $1
end tell
EOF
#!/bin/sh
ord() {
printf '%d' "'$1"
}
TRANSLATIONS=([106]=126 [107]=125 [104]=123 [108]=124 [102]=36 [97]=53)
until [ "$INPUT" == "q" ]; do
read -n 1 -s INPUT
char=$(ord $INPUT)
keycode=${TRANSLATIONS[$char]}
if [ "x$keycode" != "x" ]; then
$(keycode $keycode)
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment