A shell script to share Address Book data between users

Jun 16, '04 11:59:00AM

Contributed by: dtannenbaum

I have two user accounts on my system, one for home and one for work. However, I have my contacts for both users in one big database because I sync to one Palm Pilot. As far as I can tell there's no cheap, easy, processor-efficient way to share an Address Book database between two users on the same computer (Apple, are you listening?). So I created this Terminal script to copy the Address Book files from one user account to the other, and then run Address Book.

Whenever I want to use the Address Book I double click on this rather than on the Address Book itself. This means that when I make changes in Address Book as one user, the changes will show up for the other users, so long as I run this script. You will of course need a slightly modified version of the script for each user account. It's quick, it's dirty, but it works.

  1. Open any text editor that can create plain text files and create a new document.
  2. On the first line type the following, substituting for user1 and user2, where user2 is the current user and user1 is the last user to make changes the Address Book. Note that this is one long line; replace the line break below with a space.
    sudo cp -R /Users/user1/Library/Application Support/AddressBook/*
      /Users/user2/Library/Application Support/AddressBook
    
    This will copy the files from the last user to modify the address book to the current user.
  3. On the second line, type:
    sudo chown -R user2: /Users/user2/Library/Application Support/AddressBook/*
    
    This will change the owner of these files to the current user so that the files can be modified.
  4. On the next two lines, type:
    open /Applications/Address Book.app
    exit
    
    This opens Address Book and exits the script.
  5. Save the file. Open a new window in Terminal and type chmod 770 (notice the trailing space!). Don't press Return yet. Instead, drag the file you've just saved over the Terminal window. Its path will print out automatically. Now you can hit Return. This step makes the file executable for you and others in your group.
I'm sure there's a way to do this in AppleScript as well, and any suggestions would be very welcome.

Comments (21)


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