Skip to content

Instantly share code, notes, and snippets.

@jelmervdl
Created August 31, 2011 11:51
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 jelmervdl/1183372 to your computer and use it in GitHub Desktop.
Save jelmervdl/1183372 to your computer and use it in GitHub Desktop.
Open Terminal Here
# 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