« »

Improving Xcode via Applescript

Every so often, I try out TextMate. It continuously gets rave reviews and every so often picks up an amazing new feature that convinces me to download it again and give it another try. So far, TextMate still isn’t my thing. I know some people absolutely love it but it just isn’t for me. I do like how it works with every scripting language that I throw at it and has some cool tools for each language, I still prefer Xcode for Cocoa programming. I’ve heard of people using TextMate for everything but Cocoa programming and I’m almost willing to give TextWrangler a toss. It’s just that TextWrangler works so darn well and is free. I’m not yet willing to shell out cash for a handful of features.

I am, however, more than willing to graft these features onto other applications. My personal favorite TextMate feature is tab completions. Basically, you can type a short version of something (say, arr) and then press tab to have it expanded into actual code (NSMutableArray *array = [NSMutableArray array];). It’s very handy and my single favorite feature of TextMate. It saves me a good amount of time.

But, as I’ve said, I prefer Xcode for Cocoa programming. Xcode doesn’t allow tab completions (as far as I know). It may get it in the next version (I hope) but I don’t want to wait. After using TextMate since Halloween, I really started to miss these completions when I went back to Xcode so I write a hack myself.

My hacks tend to involve applescript. Indeed, that’s the key to this hack. I wrote a small script that gets whatever is immediately behind (before?) the insertion point, goes to the end of that word, and then uses that word to look up a key in a property list file to find some text to replace it with.

The next trick was to make it useful. There isn’t much good for this script if I have to mouse around and activate it from a scripts menu or something. That’s actually more work. I decided then to turn to Fast Scripts. Fast Scripts is a nice tool that adds some extra features to the standard scripts menu. For this hack, I needed Fast Script’s ability to assign keyboard shortcuts. Now everything works as expected. Good stuff.

The script is available below. Currently, it only works with Xcode and TextWrangler but I intend to expand it to work with other applications as well.

Download Expand snippet script.

Leave a Reply