/
ab-query.rb
57 lines (40 loc) · 1 KB
/
ab-query.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/ruby -w
# $Id: ab-query.rb,v 1.5 2004/03/21 15:07:41 sam Exp $
$:.unshift File.dirname($0)
require 'osx-wrappers'
require 'getoptlong'
require 'vpim/vcard'
require 'osx-wrappers'
HELP =<<EOF
Usage: ab-query.rb [--me] [--all]
Queries the OS X Address Book for vCards.
-h, --help print this helpful message
-m, --me list my vCard
-a, --all list all vCards
EOF
opts = GetoptLong.new(
[ "--help", "-h", GetoptLong::NO_ARGUMENT ],
[ "--me", "-m", GetoptLong::NO_ARGUMENT ],
[ "--all", "-a", GetoptLong::NO_ARGUMENT ]
)
abook = nil
opts.each do |opt, arg|
case opt
when "--help" then
puts HELP
exit 0
when "--all" then
abook = OSX::ABAddressBook.sharedAddressBook unless abook
abook.people.to_a.each {
|person|
puts person.vCard
}
when "--me" then
abook = OSX::ABAddressBook.sharedAddressBook unless abook
puts abook.me.vCard
end
end
unless abook
puts HELP
exit 1
end