Created
August 31, 2011 11:51
-
-
Save jelmervdl/1183372 to your computer and use it in GitHub Desktop.
Open Terminal Here
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
# Get the current application | |
tell application "System Events" to set current_app to the name of the first process whose frontmost is true | |
# Try to get the folder to the current open document of this application | |
# Fall back to the users home if that doesn't work | |
try | |
tell application current_app | |
set current_win to the first window | |
set path_to_file to the path of the document of current_win | |
set pwd to "`dirname \"" & path_to_file & "\"`" | |
end tell | |
on error | |
set pwd to "$HOME" | |
end try | |
# Open the terminal and `cd` to the found path. | |
tell application "Terminal" | |
do script "cd \"" & pwd & "\" && clear" | |
activate | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment