Arvont Hill: Let another user on your Mac use your iTunes Library

Friday, February 2, 2007

Let another user on your Mac use your iTunes Library

The following script allows one user to copy his iTunes library to another user. The user receiving the library will then have read access to all of the files in the library of the original user.


1. Make sure iTunes is not running on either account

2. Give read access to the Music folder of the original user with

chmod -R 755 /Users/sourceuser/Music
Where sourceuser is the username of the person sharing his library

3. Here's the script. Copy and paste it into an editor and save it as copyituneslib. You have to make the script executable, so start up Terminal.app and run

chmod 755 copyituneslib


Start copying here.

#!/bin/bash

if test -z "$2";
then echo "Usage: sudo copyituneslib sourceuser destinationuser";
exit;
fi

#copies my "iTunes Library" file to another user
#i have to set permissions on my iTunes folder to allow
#everyone to read it though.
#you also have to run this script as an administrator with the sudo command.

#you will have to do this once
#chmod -R 755 /Users/sourceuser/Music
#Where sourceuser is the username of the person sharing his library

#This means anyone with access to your computer will have read
#access to every file in the Music folder

cp /Users/$1/Music/iTunes/iTunes\ Library /Users/$2/Music/iTunes/iTunes\ Library

#since this whole script has to be run as root(a.k.a. administrator)
#we have to change the owner back to a normal user
chown $2 /Users/$2/Music/iTunes/iTunes\ Library

echo
echo
echo "Check to see that the library was copied."
echo "If it didn't work, make sure iTunes on the destination account"
echo "is not running"
echo



4. Run the script. If you saved it somewhere in your path you can just type

sudo copyituneslib sourceuser destinationuser

or else you have to type

sudo ./copyituneslib sourceuser destinationuser

provided copyituneslib is in your working directory.