Skip to content

Instantly share code, notes, and snippets.

@curiositycasualty
Last active August 29, 2015 14:07
Show Gist options
  • Save curiositycasualty/c18cb01359f7756cf03c to your computer and use it in GitHub Desktop.
Save curiositycasualty/c18cb01359f7756cf03c to your computer and use it in GitHub Desktop.
iTerm/OSA functions
# use applescript to activate an application by name
function activate() {
app=$1;
echo "tell application \"$app\" to activate" | osascript;
}
# use applescript open a new iTerm (horizontal) pane with a given command to run as an argument
function new_hpane() {
cmd=$1;
activate "iTerm";
echo "tell application \"System Events\" to tell process \"iTerm\" to keystroke \"d\" using {command down, shift down}\ntell application \"System Events\" to tell process \"iTerm\" to keystroke \"$cmd\"\ntell application \"System Events\" to tell process \"iTerm\" to key code 52" | osascript;
}
# use applescript open a new iTerm (vertical) pane with a given command to run as an argument
function new_vpane() {
cmd=$1;
activate "iTerm";
echo "tell application \"System Events\" to tell process \"iTerm\" to keystroke \"d\" using command down\ntell application \"System Events\" to tell process \"iTerm\" to keystroke \"$cmd\"\ntell application \"System Events\" to tell process \"iTerm\" to key code 52" | osascript;
}
# default to new horizontal iTerm panes
alias new_pane="new_hpane"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment