Textmate Emulation Applescripts for Coda
Update: TEA for Coda documentation and other information has now moved over to One Crayon:
http://onecrayon.com/tea/coda/
Textmate is a fantastic editor. Every once in a while I try a different text editor, but none of them allow me to get even close to the speed and productivity that I enjoy with Textmate.
However, I recently took another look at Coda when it was updated to version 1.5 because the update came out at the same time that a project which benefited a lot from Coda’s all-in-one interface hit my plate (gotta love remote editing with SSH access in the other split). Although nothing can salvage Coda’s craptastic CSS editing (nothing but a straight-up duplication of CSSEdit‘s fantastic auto-complete and intelligent indentation, that is) with a little Applescript I was able to emulate four of the functions from Textmate that I find absolutely critical to my coding happiness and productivity. Without further ado, I give you the Textmate Emulation Applescripts for Coda:
TEA for Coda currently offers four of my favorite actions from the Textmate HTML and Hyperlink Helper bundles (in slightly less elegant and feature-rich implementations, of course, given that it’s Applescript and Coda’s less-powerful editing environment):
- Insert Open/Close Tag: this is the functionality that I can’t live without. Just type the tag you want and run the script to have the tag automatically created and your cursor inserted inside (you can also type a tag with attributes, select it, and the script will intelligently exclude the attributes from the closing tag). The only thing that makes me sad is that Coda doesn’t have Textmate’s intelligent text indentation, so adding divs with the script is still a little frustrating.
- Tidy HTML: this runs Tidy HTML optimized to correctly indent your code rather than clean up messy code (Coda lacks automatic code indentation, and I write clean code anyway; see the Read Me for info on changing Tidy’s default options if you’d rather use it to fix Word HTML, for instance).
- Wrap Selection in Link: this mimics the basic functionality of Textmate’s Hyperlink Helper Wrap Word as Link, but without the cool automatic title attribute generation or tab controls. It will automatically grab whatever’s on the clipboard, though, making it easy to create links if you’ve copied them from elsewhere.
- Wrap Selection in Tag: use this script to wrap the selected text in an arbitrary tag. Like Textmate, it allows you to enter attributes but doesn’t stick them in the closing tag. Unlike Textmate, it forces you to use enter the tag in a dialog box; about the same speed, but much less elegant.
Make sure after installing the scripts that you customize yourself some shortcuts either using the System Preference Keyboard and Mouse area, or with a utility like FastScripts. The ReadMe includes a list of the default Textmate shortcuts for your reference if you’re a Textmate user.
Hopefully these scripts will help other people who want to leverage the awesome HTML editing capabilities of Textmate along with the all-in-one sweetness of Coda. If you’re an Applescript ninja and decide to improve on or add to the scripts, please let me know! I’d love to implement better solutions to my own workflow, and I’m a bit of an Applescript noob so the scripts could doubtless be improved.
As far as my own plans for the bundle go, I intend to add a script to emulate Textmate’s Wrap Each Selection in Open/Close Tag and I’m also hoping to increase the intelligence of some of the scripts by offloading some of the logic to shell scripts; just need to work on my Python-fu or something before that can happen.
While Coda is still a jack of all trades and master of none, the TEA for Coda bundle has at least made it usable for me on those projects where its collection of features and awesome split abilities make it a better choice than Textmate. I just hope that Panic will implement some intelligent indentation for a future version, as that’s still the most glaring omission when trying to perform basic text editing, even with TEA for Coda installed.
Minor update Sept. 1, 2008: With thanks to Brian Haslanger, Format with Em (menu title: Em) and Format with Strong (menu title: Strong) are now a part of the TEA for Coda. If you’ve already installed the bundle, just redownload, copy the HTML/Format folder into your ~/Library/Scripts/Applications/Coda/HTML folder, and add the cmd-I and cmd-B shortcuts in System Preferences.
Minor update Sept. 2, 2008: TEA for Coda now includes the most recent version of Tidy (the HTML Tidy site provides binaries that are several years out of date). Additionally, the Tidy script will now accept selected text and only tidy that text (without inserting a bunch of useless body tags and so forth). If you don’t select any text, it will tidy the entire document. I’ve also revised the tidy_config.txt file to some more sensical defaults. Updating procedure is the same as before.
Minor update Sept. 25, 2008: TEA for Coda now has a dedicated landing page; please reference that for the most up-do-date information about the scripts. I’ve also updated the scripts with bug fixes and more, but I won’t be updating this post any more when I update the scripts down the road.
Minor update Nov. 10, 2008: So I lied about never updating this again; since this post continues to be a popular landing spot for Google, I wanted to let folks know that TEA for Coda now includes a Universal Binary version of Tidy HTML. If you’re using a PPC, definitely grab the download above and update (more info on updating in the Read Me, or here).
Minor update Nov. 11, 2008: TEA for Coda now requires Coda 1.6 (which is a free update for all Coda users), and the scripts will now perform their actions in the active document, even if there are multiple windows open.

I currently use 

