Skip to content

Instantly share code, notes, and snippets.

@rickcnagy
Last active August 29, 2015 14:00
Show Gist options
  • Save rickcnagy/11154663 to your computer and use it in GitHub Desktop.
Save rickcnagy/11154663 to your computer and use it in GitHub Desktop.
Run a script in a specific directory in Terminal.app - OS X, via AppleScript. Useful for running scripts from a text editor, such as Sublime or TextMate. SCRIPT_PATH must be the path of the script. TextMate_RunInTerminal.sh is the specific code to make this work natively in TextMate.app.
tell application "Terminal"
set dir to "SCRIPT_PATH"
set scriptString to quoted form of dir
if (count of windows) is 0 then
do script
else
if length of (get windows whose miniaturized is false) is 0 then
set miniaturized of the front window to false
end if
do script "clear" in front window
end if
do script scriptString in front window
end tell
tell application "System Events" to set frontmost of process "Terminal" to true
#!/bin/bash
osascript -e "
tell application \"Terminal\"
set dir to \"$(echo $TM_FILEPATH | sed 's,[\\"],\\&,g')\"
set scriptString to quoted form of dir
if (count of windows) is 0 then
do script
else
if length of (get windows whose miniaturized is false) is 0 then
set miniaturized of the front window to false
end if
do script \"clear\" in front window
end if
do script scriptString in front window
end tell
tell application \"System Events\" to set frontmost of process \"Terminal\" to true
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment