|
|
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!
Related Shell Script Programming articles:
✔ Secretly capture screenshots on my Mac?
When I used to work on a Linux system, there was a utility we had that would let me take screen captures every...
✔ Parsing "id" strings in a Shell Script?Hello Dave. I need a Bash shell script that creates a directories with the group names automatically when user logs in to the...
✔ Copy and Paste from the Mac OS X Command Line?I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes,...
✔ Script to test line lengths for Twitter compatibility?I've been tasked with writing a series of tweets for a Black Friday marketing campaign and am finding it a bit tricky because...
✔ Shell script to convert lowercase to title case?As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that...
Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help
right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
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? Reader Comments To Date:
Rather amazingly, there are no comments on this article yet.
I do have a comment, now that you mention it!Check This Out Too... |
Recent Entries
Look for Answers
Recommended
All Our Categories
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and Blogging Building Web Site Traffic Business and Management Computer and Internet Basics d) None of the Above Facebook Help Google Gmail Help Google Plus Help HTML, JavaScript and Web Site Programming Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Kindle Fire Help Mac OS X Help Pay Per Click (PPC) Advertising Pinterest Help 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 Find Me on Google+ ADT on G+ |