Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A shell script to share Address Book data between users Apps
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.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[7,545 views]  

A shell script to share Address Book data between users | 21 comments | Create New Account
Click here to return to the 'A shell script to share Address Book data between users' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A shell script to share Address Book data between users
Authored by: readparse on Jun 16, '04 02:09:07PM
Interesting, although copying the address book back and forth seems like not the best way to share the data. It seems to me like a symlink is the way to go.

As a proof of concept, I just tried this on my machine. I copied the ~/Library/Application Support/AddressBook directory of my main user to /usr/local/PublicAddressBook (for lack of a better location and name) and then, for each user, after backing up their address book...

mv AddressBook AddressBook.backup

... then I created a symlink...

ln -s /usr/local/PublicAddressBook AddressBook

Boom, it works. Each user can read and write to the same data in real time. When one person updates the address, the next time the other person goes to that address, they see the latest info.

As for race conditions when both want to update at the same time... well, that probably means you've outgrown the default Address Book and need something designed for such a thing.

My only point here is that linking instead of copying is probably the way to go.

[ Reply to This | # ]

two possible buga-boos
Authored by: SOX on Jun 16, '04 02:58:01PM
Unless both of your users are Admin users, You will have to make sure both users share a group ID and that the file is writable by that group.

also one thing to watch out for is that the addressbook program may possibly delete and recreate the addressbook from time to time (as for example iTunes and iPhoto do with their databases). if so you will periodically have to restore the group priveledges.

[ Reply to This | # ]

Why not...
Authored by: Dale Mox on Jun 16, '04 03:54:29PM

Why not:
1) stick the database in the /Users/Shared folder (thus the name)
2) make a soft link to in from each user's folder
3) create a 'shareaddress' group in NetInfo and add the necessary users to it
4) set the file in /Users/Shared to that group

Then everybody can read it and edit it and so on...

Dale



[ Reply to This | # ]
Why not...
Authored by: readparse on Jun 16, '04 04:09:27PM

Yeah, that's a good idea. I should never post when I'm in a hurry, because I always leave stuff out. Like the permissions issue. I set the permissions on the PublicAddressBook to 777, which is certainly not the ideal way to do it.

I agree that there should be a group that has access to the global address book and those users needing access to it should be in that group.

The other difference is that I put in in /usr/local... /Users/Shared is a better idea.

Another thought... the best thing about a public address book is that it allows you to share those addresses while still being able to maintain private addresses of your own. So the idea solution to this would allow users to share an address group but not the entire book.

Food for thought.



[ Reply to This | # ]
Why not...
Authored by: readparse on Jun 16, '04 05:48:03PM

Yeah, that's a good idea. I should never post when I'm in a hurry, because I always leave stuff out. Like the permissions issue. I set the permissions on the PublicAddressBook to 777, which is certainly not the ideal way to do it.

I agree that there should be a group that has access to the global address book and those users needing access to it should be in that group.

The other difference is that I put in in /usr/local... /Users/Shared is a better idea.

Another thought... the best thing about a public address book is that it allows you to share those addresses while still being able to maintain private addresses of your own. So the idea solution to this would allow users to share an address group but not the entire book.

Food for thought.



[ Reply to This | # ]
A shell script to share Address Book data between users
Authored by: atter_cob on Feb 08, '05 03:04:23PM

I've noticed that the files keep getting larger and larger...

I have the addressbook shared between two machines. (The disk that the files are on is shared.) I've noticed that each time I access the file from one machine, it gets bigger even if I don't add anything.



[ Reply to This | # ]
I use iSync & .Mac
Authored by: mr_rangr on Jun 16, '04 04:25:30PM

My wife and I have separate accounts, but share iCal and Address Book data.
Using iSync and .Mac, both of our accounts are pretty well in sync. We also have an iBook and cellphones that stay in sync with this setup.



[ Reply to This | # ]
iSync works fine
Authored by: schaps on Jun 16, '04 10:27:14PM

You need to have .Mac, but if you do, it works great between my two user accounts on my Powerbook (one home, one for work).

And if you don't have .Mac, I think it is a pretty decent deal considering the service and software you get. It's going to be a better deal when the up the storage space to more than 100 MB.

T



[ Reply to This | # ]
A shell script to share Address Book data between users
Authored by: miles_thatsme on Jun 16, '04 05:01:46PM

I don't regularly use multiple accounts on the same machine, but couldn't you use the terrific, free, Address-o-Sync, http://www.versiontracker.com/dyn/moreinfo/macosx/21360, running on both accounts, to do the same? It's quite customizable and easy to use...



[ Reply to This | # ]
A shell script to share Address Book data between users
Authored by: designr on Jun 16, '04 10:33:08PM

As is described in this hint:

http://www.macosxhints.com/article.php?story=20030304214738124&query=designr

You can easily share desktops, documents folders and libraries, etc. between users. In this case, throw the address book database and prefs files (i.e.: ~/Library/Application Support/AddressBook/) into the Shared Folder and create links to it (them) in the appropriate places of the two Users home directories. Make sure the permissions give both users read/write access and you're done. Then both users can use the same address book (not at the same time though).



[ Reply to This | # ]
Here's an idea.
Authored by: gxw on Jun 16, '04 11:19:33PM

Here's what I'd try to accomplish this.
1. Copy the address book to a folder off the root Or somewhere more appropriate.
2. Make that folder readable & writable by the user accounts you want to share the address book between.
3. Log in as each user & create a symbolic link in the address book folder that points to the shared location (man ln)

Drawback
Simultanious updates would probably not work. Possibly only one user at a time can have the address book open.

Have not tried this in OS X but this is the way I'd do it in Linux.



[ Reply to This | # ]
Here's an idea.
Authored by: gxw on Jun 16, '04 11:21:08PM

Uh oh.
Too slow to post - see first reply.



[ Reply to This | # ]
Here's an idea.
Authored by: uli_the_knecht on Jun 17, '04 12:29:01AM

The best way to solve the problem with user permission would be to save the user-data on a separate partition. then you can set the option to ignore the permissions (information window of the partition).

regards, uli the knecht



[ Reply to This | # ]
A shell script to share Address Book data between users
Authored by: flyingcactus on Jun 17, '04 12:35:23AM

I have been using the symlink idea for a while now and it works well. The only draw back is that the changes that are made while the program is open are written to the file when you quit the program. This means that if two users are using the same Addressbook or iCal database, at the same time, then only one users changes will be saved, specifically the last person that closes the program.

To avoid this problem be sure that the other users do not have the program open, and that you close the programs right after you are done to be sure your changes are written to the file.



[ Reply to This | # ]
A shell script to share Address Book data between users
Authored by: Gigacorpse on Jun 17, '04 08:11:48AM

Doesn't Mac OS X client come with slapd included? If so, you should be able to run a local LDAP server and have Mail sync to that.

Personally, I would like to see Apple's Address Book support an option of including addresses from a system wide address book that the administrator could set up, which would reside in /Library/Address Book/ (or something like that).



[ Reply to This | # ]
A shell script to share Address Book data between users
Authored by: jocknerd on Jun 17, '04 12:42:49PM

I'd like to see Apple make a lot of their app's data available in a global area. Such as iPhoto, iTunes, Address Book.

---
OS X 10.2
Apple Styling, Unix Power



[ Reply to This | # ]
A shell script to share Address Book data between users
Authored by: cyberassassin on Jun 17, '04 12:44:00PM

The best thing for apple to do is provide the ability to subscribe to address books via rendezvous on the network. This is something every office needs and wants. That way you can have one person be responsible for the company wide directory.....

---
Who is the Master of Foxhounds,
and who says the hunt has begun?
-- Pink Floyd



[ Reply to This | # ]
A shell script to share Address Book data between users
Authored by: quentinsf on Jun 18, '04 10:06:41AM

I wish, oh I wish, that something would provide an easy and reliable way to update LDAP databases. Most things connect to them and search them but most can't update them. And the things that can aren't generally things I want to use.

Now, Apple - that would be a really useful addition to Address Book...



[ Reply to This | # ]
A shell script to share Address Book data between users
Authored by: mchadwick on Jun 17, '04 01:03:10PM

Good hint with other applications! I now copy ths directory when I perform my backups. Should my hard drive fail again, I can just drop this directory into place and I'm in good shape.

What I'd realy like to see is an appple script or shell script to export contacts with a similar result to dragging and dropping all vCards from the GUI app.



[ Reply to This | # ]
iSync not quite there for multi-user
Authored by: wjlyerly on Jun 18, '04 07:51:23AM

iSync has one big issue with multiple users. The 'this-is-me' card gets synced as well. If you sync between two people, they both end up being identified as the same person. This means the same system icon in the login window, the same icon for iChat, etc.

Otherwise it works pretty well, but that's a killer for me.



[ Reply to This | # ]
A shell script to share Address Book data between users
Authored by: pooduck on Jun 18, '04 12:46:31PM

The duplication of the "this is me" card was a killer in my case too - one of the reasons I didn't renew my .Mac account.

Address-O-Matic looks like a promising solution for LAN-based Address Book sharing. It's currently in beta, but in my testing it works as described - allowing an Address Book to "publish" addresses and share them via Rendezvous™. Other users on the LAN can then "subscribe" to them and voila! the published addresses appear in the subscriber's Address Book.

http://www.address-o-matic.com/



[ Reply to This | # ]