Written October 28, 2007. Tagged OS X, TextMate, AppleScript, Design.
By request, I did an "Open In TextMate" Finder toolbar icon for Leopard.
I also took the opportunity to write a new script, based on Simon Dorfman's. Clicking the toolbar icon now opens the selected file or files if there is a selection; otherwise it opens the current directory. You can also drag-and-drop files to the icon to open those.
Behind the scenes, the script is all AppleScript, without dropping into the shell. Feels a bit more robust.
A single TextMate window will open, containing all selected or dropped items in a project.
I put my icon inside the bundle, so it should appear with no extra effort. I also toggled a flag in the bundle so you don't see the script appear and disappear in the dock when triggered.
Download OpenInTextMate.zip, extract the file somewhere (I keep it in /Applications/Scripts
), then drag it onto the Finder toolbar. You'll need to wiggle it a bit for the toolbar to catch on.
If you like your toolbar all grayscale, feel free to use (save the linked icon file, not the displayed PNG image) instead, and copy it into the script as described here.
The code:
-- Opens the currently selected Finder files, or else the current Finder window, in TextMate. Also handles dropped files and folders.
-- By Henrik Nyh <https://henrik.nyh.se>
-- Based loosely on http://snippets.dzone.com/posts/show/1037
-- script was clicked
on run
tell application "Finder"
if selection is {} then
set finderSelection to folder of the front window as string
else
set finderSelection to selection as alias list
end if
end tell
tm(finderSelection)
end run
-- script was drag-and-dropped onto
on open(theList)
tm(theList)
end open
-- open in TextMate
on tm(listOfAliases)
tell application "TextMate"
open listOfAliases
activate
end tell
end tm