Applescript to launch iTerm2 Version 3+ from OS X Finder via keyboard shortcut or Toolbar
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 or later. 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. Update - The original author released a build script for the newer iTerm2 versions at https://github.com/peterldowns/iterm2-finder-tools that keeps the original behavior of reusing an open iTerm2 window.
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
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
pdanford - Jan 2017. MIT License, etc.