Open iTerm Here
I've been using iTerm for over a year now. I like it over Terminal for a
few reasons, but primarily because it supports multiple frames. This
makes my workflow easier as I can see everything on a single screen and
can easily navigate from one frame to the other without reaching for the
mouse. I've additionally abandoned MacVim for Vim. Now, I can do most
everything I need in a single, maximized, iTerm window. But I get
annoyed with opening iTerm and having to navigate to the directory of my
current desire. Most of the time, I am already browsing the desired
directory in Finder as I begin a hacking session.
What is a guy to do?
AppleScript to the rescueI created an AppleScript app based on work from a couple of other folks, whom I've given attribution. The AppleScript launches iTerm and changes to whatever directory was active in Finder. If iTerm is running, the script opens a new terminal. If iTerm is not running, the script launches it and changes directories accordingly.
iTerm Here - Michael "Doc" Norton
A Button for opening the iTerm.app and CD-ing to the location of the selected files or folder.
Inspired by the workflow from Jeroen Leenars, but using iTerm instead of Terminal.
Additional contributions to concept (and code) from:
See http://fmeneguzzi.blogspot.com/2009/09/open-iterm-here.html for more information.
See http://putnamhill.net/applescript/open-iterm-here for more information.
tell application "Finder"
set this_folder to (the target of the front window) as alias
set this_folder to startup disk
on open these_items
repeat with i from 1 to the count of these_items
set this_item to item i of these_items
set thePath to (quoted form of POSIX path of this_path)
set iTermRunning to isAppRunning("iTerm")
tell application "iTerm"
if iTermRunning then
set myTerm to (make new terminal)
tell myTerm to launch session "Default Session"
set myTerm to first terminal
tell myTerm to activate current session
tell the last session
write text "cd " & thePath & "; clear"
tell application "System Events" to set app_list to every application process whose name is app_name
if the (count of app_list) > 0 then
You can use the script for yourself.
- Paste it into the Script Editor application and save it as an application.
- In Finder, navigate to the application and drag it to the Finder bar.
- You can now click the button and it will open the foremost directory in Finder.
- Or you can drag and drop folders onto the icon.
- Locate iTerm and Select the More Info... button.
- Locate your new app and Select the More Info... button.
- Copy the small icon from the top-left of the iTem Info window.
- Paste it onto the small icon of your app's Info Window.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)