
Can I use my Palm Desktop address book data in shell scripts?
Dave, I have a pile of addresses in my Palm Desktop address book on my Mac, but I'd really like to be able to use them from within some shell scripts, particularly to be able to build a quick reference of names and phone numbers. Is that even possible?
This is the kind of question I like to get, obscure and challenging! Let's see what we can figure out... First off, there's really no way to easily swoop into the Palm Desktop database directly and manipulate data, so we're going to need to export the address book into a text file. Launch Palm Desktop then choose File -> Export... That dialog box offers you the choice of modules to export (Date Book, ToDos, Addreses or Memos), a crude filter you can apply, and an output format. The output format choices vary based on the kind of data being exported, and for the Addresses, the options are "tab and return", "Palm Desktop" or "vCard". You'll want to choose Addresses, All Addresses and tab and return as the three choices, as shown here:
![]() click on the image for a full size view
This will generate a text file that can almost be manipulated by shell commands. The problem is that each line of the export has the wrong line-termination sequence. Try using a command like head outputfile to see what I mean. To correct the carriage return sequences, assuming that the Palm Desktop output file is called "my-address-book", do this: $ tr '\015' '\012' < my-address-book > address-book-fixedNow, finally, we have a file we can work with! To extract specific columns of data, since it's all well formed and separated with tabs, we can use either perl, awk or even cut to accomplish our task. I'm going to use awk because I like the program and because cut has an annoying habit of not understanding basic Unix escape character sequences (e.g., \t for tab). Using awk here's how I would extract the first and last name followed by the first phone number listed in the entry: $ awk -F\t '{ print $1,$2 ": "$24 " ("$23")" }' \
address-book-fixed | head -2
First Name Last Name: Phone 1 (Phone 1 Label)
Dave Taylor: (303) 555-1234 (Work)
To generate the list you seek, simply replace the "| head -2" in the above command with a new filename:
$ awk -F\t '{ print $1,$2 ": "$24 " ("$23")" }' \
address-book-fixed > name-and-phone-number
This produces a simple text file that lists all the names and phone numbers of your contacts. A quick alias and you can easily have a simple command-line-based phone lookup system:
alias phone="cat ~/name-and-phone-number | grep -i"Now you can just type phone john and get a quick list of all matches. Using a very similar approach, you could also export your date book and produce a quick list of all birthdays, then feed that into the cron system and automate emailing happy birthday messages to all your friends and family too!
Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.
Categorized:
Mac OS X Help
, Shell Script Programming
(Article 3814)
Tagged: Previous: Does -prune work like -maxdepth in Unix "find" on AIX? Next: What are eBay's Refer a Friend and Anything Points programs? Subscribe!
Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.
Rather amazingly, there are no comments on this article yet.
I have a lot to say, but ...
I do have a comment, now that you mention it!
|
Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.
Help!
Subscribe to
Ask Dave Taylor!
Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.
Articles and Reviews
Auctions and Online Shopping Blogs and RSS Feeds Building Web site traffic Business and Management Cell Phones and Mobile Phones CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above HTML and CSS Mac OS X Help MySpace, Facebook, Twitter and Social Network Help Pay Per Click (PPC) Search Engine Optimization Shell Script Programming Sony PSP, MP3 Players, Etc. The Writing Business Unix and Linux Help Video Game Tips and Help Windows Help
Recent Entries
Join the List!
Book Links
|