Skip to content

Instantly share code, notes, and snippets.

@jpalumickas
Last active July 1, 2021 11:36
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jpalumickas/6470791 to your computer and use it in GitHub Desktop.
osaScript Ruby examples
# === Terminal.app === #
# Open new tab in terminal.
exec("osascript -e 'tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down' > /dev/null 2>&1 ")
# Open directory
exec("osascript -e 'tell application \"Terminal\" to do script \"cd directory\" in selected tab of the front window' > /dev/null 2>&1 ")
# Open directory in new tab (this is better)
exec("osascript -e 'tell application \"Terminal\"' -e 'tell application \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down' -e 'do script with command \"cd directory && clear\" in selected tab of the front window' -e 'end tell' > /dev/null 2>&1")
# === iTerm.app === #
exec("osascript -e 'tell application \"iTerm\"' -e 'make new terminal' -e 'tell the first terminal' -e 'activate current session' -e 'launch session \"Default Session\"' -e 'tell the last session' -e 'write text \"cd #{value}\"' -e 'write text \"clear\"' -e 'end tell' -e 'end tell' -e 'end tell' > /dev/null 2>&1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment