Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Finder Open iTerm Here: Drop a folder on this script (or just run it) to open a new iTerm window there. If the selected item isn't a folder, it will open the item's parent folder. Great when bound to a hotkey in FastScripts or added to the Finder Sidebar. Works with iTerm2-v3 (2.9)
* Finder Open iTerm Here - v1.0.2 - 4/14/2011
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
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
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"
if (count of windows) = 0 then
set theWindow to (create window with default profile)
set theSession to current session of theWindow
set theWindow to current window
tell current window
set theTab to create tab with default profile
set theSession to current session of theTab
end tell
end if
tell theSession
write text "cd " & myPath
end tell
end tell
end open_iTerm

This comment has been minimized.

Copy link

@warmhug warmhug commented Jun 2, 2016

It's a great gist, thank you. Another question, how to save it as an app, and put it in XtraFinder's toolbar like this ?


This comment has been minimized.

Copy link

@jr180180 jr180180 commented Jul 25, 2016

When you open up Automator, you want to select "Application." Then, just save it and it should be saved as a ".app"

To change the icon, see "Changing an item's icon" at

Once you've changed it, hold down "command" and then drag it into the toolbar. (I know this works for the built in toolbar. Not sure about XtraFinder but it's worth a shot.)

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