find email address in address book (was Re: [TxMt] Sorry)
Grant Hollingworth
grant at antiflux.org
Tue Nov 7 23:21:19 UTC 2006
* Brett Terpstra <brett at circlesixdesign.com> [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 bash_init.sh for /usr/bin/env scripts.
-------------- next part --------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>bundleUUID</key>
<string>B7BC3FFD-6E4B-11D9-91AF-000D93589AF6</string>
<key>command</key>
<string>#!/usr/bin/env ruby -wKU
SUPPORT = ENV['TM_SUPPORT_PATH']
DIALOG = SUPPORT + '/bin/tm_dialog'
require SUPPORT + '/lib/escape'
require SUPPORT + '/lib/plist'
require SUPPORT + '/lib/exit_codes'
search_text = STDIN.read
names = []
data = %x{contacts -HSs -f "%n:%e:" "#{search_text}"}
data.scan(/(.*)?:(.*)?:/){|name,email|
if !email.empty?
names << {
'title' => "#{name} (#{email})",
'email' => "#{name} <#{email}>"
}
end
}
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>
<key>fallbackInput</key>
<string>word</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>
<string>^@A</string>
<key>name</key>
<string>Find Email Address in Address Book</string>
<key>output</key>
<string>replaceSelectedText</string>
<key>uuid</key>
<string>575C4CAF-71B1-4F92-886B-8D89E0D0EFDD</string>
</dict>
</plist>
More information about the textmate
mailing list