A command-line-only basic phonebook script

Jun 09, '03 08:59:00AM

Contributed by: macubergeek

I find Apple's Address Book an excellant tool, but sometimes I just want to quickly lookup a person's phone number. Here's a shell script to create a phone book and search the phone book. It creates a phone book called ~/.phonebook in your home directory. To find out the useage of the script do: pb -help or pb help or just pb h. To add a user do pb add Joe Blow PhoneNumber. If you enter a phone number like (123)456-7890, then put double quotes around it: "(123)456-7890"

Cavaet: be sure to double check for linewraps (the backslash line endings) in the below script code:

#!/bin/sh
case $1 in
h | help | -h | -help) echo "Useage:"
  echo "To add a user to the phonebook do: pb add Joe Blow 123-456-8900"
  echo "To remove a user from the phone book do:
  echo "pb delete <first or last name>"
  echo "NOTE: when deleting a user be sure to use either \
  first or last name, whichever is unique."
  echo "If you use parens in your phone number be sure to put \
  double quotes around the phone number."
esac

case $1 in
  # add) echo $2 >> ~/.phonebook;;
  add) echo $2 $3 $4 >> ~/.phonebook;;
  delete) cat ~/.phonebook | grep -v $2 > /tmp/phonebook && \
    mv /tmp/phonebook ~/.phonebook;;
esac

case $1 in
  f | find | -f | -find) egrep $2 ~/.phonebook;;
esac
[robg adds: I haven't tested this script as I use my Palm or AddressBook to find information. But if you spend most of your time in the Terminal, this could be a helpful script.]

Comments (21)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030605133420634