Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I think the title states exactly what I want to do. I want a shortcut or even a button within Finder which fires up a new iTerm Tab and changes the location to the location i've open in Finder. Some sort of open . in reverse. :-)

Thank you, Malax

share|improve this question

4 Answers

up vote 5 down vote accepted

There is an Open Terminal Here AppleScript that you should be able to modify to call iTerm instead. This MacOSXHints post should be helpful as well.

(I'm not on my Mac otherwise I would test it.)

share|improve this answer
Thank you a lot! – Malax Jan 8 '10 at 20:23

This applescript works for me:

-- script was opened by click in toolbar
on run
tell application "Finder"
    try
        set currFolder to (folder of the front window as string)
    on error
        set currFolder to (path to desktop folder as string)
    end try
end tell
CD_to(currFolder, false)
end run

-- script run by draging file/folder to icon
on open (theList)
set newWindow to false
repeat with thePath in theList
    set thePath to thePath as string
    if not (thePath ends with ":") then
        set x to the offset of ":" in (the reverse of every character of thePath) as string
        set thePath to (characters 1 thru -(x) of thePath) as string
    end if
    CD_to(thePath, newWindow)
    set newWindow to true -- create window for any other files/folders
end repeat
return
end open

-- cd to the desired directory in iterm
on CD_to(theDir, newWindow)
set theDir to quoted form of POSIX path of theDir as string
tell application "iTerm"
    activate
    delay 1
    -- talk to the first terminal 
    try
        set myterm to the first terminal
    on error
        set myterm to (make new terminal)
    end try

    tell myterm
        try
            -- launch a default shell in a new tab in the same terminal 
            launch session "Default Session"
        on error
            display dialog "There was an error creating a new tab in iTerm." buttons {"OK"}
        end try
        tell the last session
            try
                -- cd to the finder window
                write text "cd " & theDir
            on error
                display dialog "There was an error cding to the finder window." buttons {"OK"}
            end try
        end tell
    end tell
end tell
end CD_to
share|improve this answer

Take a look at the cdto project hosted on code.google.com "Fast mini application that opens a Terminal.app window cd'd to the front most finder window. This app is designed (including it's icon) to placed in the finder window's toolbar." Also has a plugin to work with iTerm.

share|improve this answer
But it opens two iTerms windows which is highly annoying after a while. – Mike Lischke 2 days ago

Using the other answers on this page I have created an App that can be dragged into the finder task bar.

You can download it from here: https://github.com/rc1/iTermTo

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.