iTerm/TextMate Here

Yes, again. Inspired by other solutions to the same problems, here are updated versions of these scripts. The primary difference is that they’re based on Apple’s droplet sample, so you can either click on them (for the current directory) or drop stuff on them and it’ll work either way. So, why don’t I just use his scripts, like I do his icons? Beats me — I updated these a week or two ago, and I’ve long since forgotten.1

There’s compiled versions of these scripts at the end of the post. They’re saved as run-only application bundles, they have the icons linked above set on them so they look all Leopard-ish, and they have LSUIElement set on them so they don’t pop up in your Dock briefly when you use them.

-- iTerm Here
-- changes inspired by
--     http://henrik.nyh.se/2007/10/open-terminal-here-and-glob-select-in-leopard-finder

on run
-- I was run normally
tell application "Finder"
    if selection is {} then
        set selectedItems to {front window's folder}
    else
        set selectedItems to selection -- as alias list
    end if
end tell
process(selectedItems)
end run

on open (theseItems)
-- Something was dropped on me
process(theseItems)
end open

on process(theseItems)
repeat with thisItem in theseItems
    tell application "iTerm"
        activate
        try
            set term to front terminal
        on error
            set term to (make new terminal)
        end try
        tell term
            set thePath to POSIX path of (thisItem as string)
            repeat until thePath ends with "/"
                set thePath to text 1 thru -2 of thePath
            end repeat
            launch session "default session"
            tell current session
                write text "cd " & quoted form of thePath
            end tell
        end tell
    end tell
end repeat
end process

{: lang=applescript }

-- TextMate Here
-- changes inspired by
--     http://henrik.nyh.se/2007/10/open-in-textmate-from-leopard-finder

on run
-- I was run normally
tell application "Finder"
    if selection is {} then
        set selectedItems to {front window's folder}
    else
        set selectedItems to selection
    end if
end tell
process(selectedItems)
end run

on open (theseItems)
-- Something was dropped on me
process(theseItems)
end open

on process(theseItems)
set theCommand to POSIX path of (path to resource "mate" in bundle (path to application "TextMate"))
repeat with thisItem in theseItems
    set thePath to POSIX path of (thisItem as string)
    set theCommand to theCommand & " " & quoted form of thePath
end repeat
do shell script theCommand
end process

{: lang=applescript }

TextMate Here.app.zipiTerm Here.app.zip


  1. While I’m at it, I’ve also forgotten what the other thing was I wanted to do to them before posting this. 

This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

Comments are closed.