Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

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?

Dave's Answer:

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:

Palm Desktop Export
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-fixed
Now, 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.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments
Rather amazingly, there are no comments on this article yet.

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









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!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]