Skip to content

Instantly share code, notes, and snippets.

@mohan-mu
Forked from jpalumickas/osascript.rb
Created August 15, 2017 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohan-mu/07b0dc8fa04f9827a10c61e955cd5944 to your computer and use it in GitHub Desktop.
Save mohan-mu/07b0dc8fa04f9827a10c61e955cd5944 to your computer and use it in GitHub Desktop.
Osascript 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