find email address in address book (was Re: [TxMt] Sorry)

Grant Hollingworth grant at
Tue Nov 7 23:21:19 UTC 2006

* Brett Terpstra <brett at> [2006-11-07 15:20]:
>This one exits properly if there is only one address found.

Very nice! Passing a list of lines to Ruby is exactly what I was thinking of. Dropping an osascript call in there should be easy... once I come up with a good one.

I fixed the sorting by adding -s to the contacts call and not reversing 'names'.

Hitting escape from the menu removed the original text. I changed that by using TextMate.exit_replace_text(search_text). Is there a way to make this work with abort? Replacing the text with itself is a bit of a kluge.

Finally, what's the best way of setting the path? I have contacts in /opt/local/bin, and I guess TextMate doesn't call for /usr/bin/env scripts.
-------------- next part --------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
	<string>#!/usr/bin/env ruby -wKU

DIALOG = SUPPORT + '/bin/tm_dialog'

require SUPPORT + '/lib/escape'
require SUPPORT + '/lib/plist'
require SUPPORT + '/lib/exit_codes'
search_text =
names = []

data = %x{contacts -HSs -f "%n:%e:" "#{search_text}"}
	if !email.empty? 
		names << {
			'title' => "#{name} (#{email})",
			'email' => "#{name} <#{email}>"
TextMate.exit_show_tool_tip "No matches found" if names.empty?
TextMate.exit_replace_text names[0]['email'] if names.length == 1

plist = { 'menuItems' => names }.to_plist
res = PropertyList::load(`#{e_sh DIALOG} -up #{e_sh plist}`)
TextMate.exit_replace_text(search_text) unless res.has_key? 'selectedMenuItem'

print res['selectedMenuItem']['email']</string>
	<string>Find Email Address in Address Book</string>

More information about the textmate mailing list