|
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!
Categorized:
Mac OS X Help
,
Shell Script Programming
(Article 3814,
Written by Dave Taylor)
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!
Rather amazingly, there are no comments on this article yet.
I have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
Recommended
Recent Entries
Search
I Need Help!
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and RSS Feeds Building Web Site Traffic Business and Management CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above Facebook Help Google Plus Help HTML and CSS Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Mac OS X Help Pay Per Click (PPC) Advertising Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help WordPress Help |