Skip to content

Instantly share code, notes, and snippets.

@funkatron
Last active February 2, 2016 16:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funkatron/f6d838ae8ad0b3e75152 to your computer and use it in GitHub Desktop.
Save funkatron/f6d838ae8ad0b3e75152 to your computer and use it in GitHub Desktop.
Open current Finder directory in iTerm
(*
* Finder Open iTerm Here - v1.0.2 - 4/14/2011
* http://benalman.com/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*
* Modified by Ed Finkler to work with iTerm 2.9x Beta - Tuesday; February 2, 2016
*)
tell application "Finder"
set mySelected to get selection as list
if (count of mySelected) is not 0 then
set myItem to first item of mySelected
if class of myItem is alias file then
set myItem to original item of myItem
end if
if class of myItem is in {file, document file, internet location file} then
set myItem to container of myItem
end if
else if the (count of window) is not 0 then
set myItem to folder of the front window
else
set myItem to path to desktop folder
end if
my open_iTerm(myItem)
end tell
on open these_items
my open_iTerm(first item of these_items)
end open
on open_iTerm(myItem)
set myPath to quoted form of POSIX path of (myItem as string)
tell application "iTerm"
activate
if the (count of window) is 0 then
set myTerm to make new session
else
set myTerm to the current window
end if
tell myTerm
set newTab to create tab with default profile
tell the last session of newTab to write text "cd " & myPath
end tell
end tell
end open_iTerm
@funkatron
Copy link
Author

I modified this: https://gist.github.com/danro/2957829 but didn't properly fork. Attribution as due.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment