Skip to content

Instantly share code, notes, and snippets.

@guiwuff
Last active October 17, 2019 19:42
Show Gist options
  • Save guiwuff/3544d156da52bda4acb3f25a708205e8 to your computer and use it in GitHub Desktop.
Save guiwuff/3544d156da52bda4acb3f25a708205e8 to your computer and use it in GitHub Desktop.
Open iTerm2 App from the context menu of the current finder folder or through shortcut

Open iTerm2 App from Finder context menu

Run iTerm2 Here listed in the context menu of the current Finder's directory, installed as a Service and can have global Keyboard shortcut

Create Service using Automator

Reference : https://gist.github.com/pdanford/158d74e2026f393e953ed43ff8168ec1 Run Automator > New Service > Action > Run Apple Script Service Received Selected Folders in Finder

Paste this code into Run Apple Script Code Area

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 the service file as : iTermOpenService

screen shot 2017-04-16 at 09 13 33

Keyboard Shortcut and Service preferences pane vis Preferences > Keyboard > Shortcut, look for iTermOpenService - enable, and create a global keyboard shortcut for the service.

screen shot 2017-04-16 at 09 20 26

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