Based on info from http://peterdowns.com/posts/open-iterm-finder-service.html but with modified behavior and fixed to work with iTerm2 Version 3+. It will not work with older versions of iTerm. The modified behavior is to open a new terminal window for each invocation instead of reusing an already open window.
- Run Automator, select a new Service
- Select Utilities -> Run AppleScript
- Service receives selected 'folders' in 'finder.app'
- Paste script:
on run {input, parameters} tell application "Finder" to set dir_path to quoted form of (POSIX path of (first item of (get selection as alias list) as alias)) CD_to(dir_path) end run on CD_to(theDir) tell application "iTerm" activate set win to (create window with default profile) set sesh to (current session of win) tell sesh to write text "cd " & theDir & ";clear" end tell end CD_to - Save as 'Open iTerm at Folder'
- Open Keyboard in System Preferences. Under Shortcuts -> Services -> Files and Folders check 'Open iTerm at Folder' (with desired keyboard shortcut - e.g. control-option-command-T)
To make an Automator App that can reside on the Finder toolbar to open an iTerm window at the current directory
- Run Automator, select new Application
- Select Utilities -> Run AppleScript
- Paste script:
on run {input, parameters} tell application "Finder" set dir_path to quoted form of (POSIX path of (folder of the front window as alias)) end tell CD_to(dir_path) end run on CD_to(theDir) tell application "iTerm" activate set win to (create window with default profile) set sesh to (current session of win) tell sesh to write text "cd " & theDir & ";clear" end tell end CD_to - Save as 'iTermOpenScript.app' somewhere out of the way
- Drag and drop the 'iTermOpenScript.app' onto the Finder toolbar while holding down the Option and Command keys
pdanford - Jul 2016