Last active
August 29, 2015 14:00
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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