Open in iTerm from Finder

May 17th, 2006

Since I’ve been asked to do it, I wrote the “Open in iTerm” app, that does the very same thing than “Open in Terminal” (except that it uses iTerm instead of Terminal.app)

Actually there could be bugs, but at least on my system I suppose it’s not my fault, but rather it is iTerm that crashes a lot (maybe the AppleScript part has not been tested extensively on intel macs).

If you experience problems, let me know.

The script part that accesses iTerm is

tell application "iTerm"
	activate
	set myTerm to (make new terminal)
	tell myTerm
		set mySession to (make new session at the end of sessions)
		tell mySession
			exec command "/bin/bash"
			write text "cd \""& myPath &"\""
		end tell
	end tell
end tell

I bundled both apps in the very same package, and you can download it here.

I upgraded this script too with Marco’s help.

on run
	tell application "Finder" to try
		set myPath to quoted form of ¬
			POSIX path of ((target of window 1) as string)
	on error
		set myPath to "~"
	end try

	tell application "iTerm"
		activate
		set myTerm to (make new terminal)
		tell myTerm
			set mySession to (make new session at the end of sessions)
			tell mySession
				exec command "/bin/bash"
				write text "cd "& myPath
			end tell
		end tell
	end tell
end run

Definitive?

After some discussion on icm and the help of tv and Marco (thank you guys) we came to this

on run

    tell app "Finder"
        try
            set myPath to quoted form of ¬
                POSIX path of ((target of window 1) as string)
        on error
            set myPath to "~"
        end
        set esiste to ((count (get ¬
            name of every application process ¬
            whose creator type is "ITRM")) is not 0)
    end

    tell app "iTerm"
        activate
        if esiste then
            set myTerm to (make new terminal)
        else
            set myTerm to the first terminal
        end if
        tell myTerm
            make new session at the end of sessions
            tell the last session
                exec command "/bin/bash"
                write text "cd " & myPath
            end
        end
    end

end

Mac, Mac Programming, Programming | Comments | Trackback

Leave a Reply

  1.  
  2.  
  3.  
  4. XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
You can keep track of new comments to this post with the comments feed.

Recent Posts

Blogroll

Siti amici

Misc

Recent Comments

Categories

Enrico Franchi graduated in Maths and Computer Science and is now studying for a Computet Science MSc (though because of italian bureaucracy that very course is to be cancelled).

RiK0's Tech Temple is using WP-Gravatar