Skip to content

Instantly share code, notes, and snippets.

@leoluyi
Forked from suewonjp/Open_iTerm2.txt
Created July 28, 2016 13:45
Show Gist options
  • Save leoluyi/d7bde24c4998b1b820a04f376f506e0c to your computer and use it in GitHub Desktop.
Save leoluyi/d7bde24c4998b1b820a04f376f506e0c to your computer and use it in GitHub Desktop.
[Mac OS X Tip] Open a new iTerm tab from the current folder in Finder
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
try
set w to first window
on error
set w to (create window with default profile)
end try
tell w
tell (create tab with default profile)
launch session "Default Session"
tell current session
write text "cd " & theDir & ";clear;"
end tell
end tell
end tell
end tell
end CD_to
@leoluyi
Copy link
Author

leoluyi commented Jul 28, 2016

  1. Convert the above applescript code to a application bundle with Automator
    • Say the converted application is Open_iTerm.app
  2. Hold down the Option + Command keys, then drag the Open_iTerm.app to the Finder toolbar.
    • The icon will be embedded into the Finder toolbar (See the above figure for what it would look like)
  3. That's it. Every time you click on the icon, a new iTerm tab will open with its current directory set to the folder where the Finder instance was associated.

The above procedure is working on my system (OS X 10.11.5 and iTerm2 build 3.0.0)

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