found drama

get oblique

synctunes

by Rob Friesel

Submitted for scrutiny (esp. since it doesn’t appear to be working…):

synctunesin.sh gets the latest iTunes Library info from the iTunes User account

#!/bin/bash

TUNESHARE=/Users/itunes/Music/iTunes
AMYLIB=/Users/amy/Music/iTunes
GUESTLIB=/Users/guest/Music/iTunes
ROBLIB=/Users/rob/Music/iTunes

if [ $USER != itunes ]; then
  if [ $TUNESHARE/iTunes\ 4\ Music\ Library -nt $AMYLIB/iTunes\ 4\ Music\ Library ]; then
    cp $TUNESHARE/iTunes\ 4\ Music\ Library $AMYLIB/iTunes\ 4\ Music\ Library
    cp $TUNESHARE/iTunes\ Music\ Library.xml $AMYLIB/iTunes\ Music\ Library.xml
  fi
  if [ $TUNESHARE/iTunes\ 4\ Music\ Library -nt $GUESTLIB/iTunes\ 4\ Music\ Library ]; then
    cp $TUNESHARE/iTunes\ 4\ Music\ Library $GUESTLIB/iTunes\ 4\ Music\ Library
    cp $TUNESHARE/iTunes\ Music\ Library.xml $GUESTLIB/iTunes\ Music\ Library.xml
  fi
  if [ $TUNESHARE/iTunes\ 4\ Music\ Library -nt $ROBLIB/iTunes\ 4\ Music\ Library ]; then
    cp $TUNESHARE/iTunes\ 4\ Music\ Library $ROBLIB/iTunes\ 4\ Music\ Library
    cp $TUNESHARE/iTunes\ Music\ Library.xml $ROBLIB/iTunes\ Music\ Library.xml
  fi
fi

exit 0

synctunesout.sh takes your playcounts, updated ratings, etc. and updates them in the central iTunes User account

#!/bin/bash

TUNESHARE=/Users/itunes/Music/iTunes
AMYLIB=/Users/amy/Music/iTunes
GUESTLIB=/Users/guest/Music/iTunes
ROBLIB=/Users/rob/Music/iTunes

if [ $USER != itunes ]; then
  if [ $AMYLIB/iTunes\ 4\ Music\ Library -nt $TUNESHARE/iTunes\ 4\ Music\ Library ]; then
    cp $AMYLIB/iTunes\ 4\ Music\ Library $TUNESHARE/iTunes\ 4\ Music\ Library
    cp $AMYLIB/iTunes\ Music\ Library.xml $TUNESHARE/iTunes\ Music\ Library.xml
  fi
  if [ $GUESTLIB/iTunes\ 4\ Music\ Library -nt $TUNESHARE/iTunes\ 4\ Music\ Library ]; then
    cp $GUESTLIB/iTunes\ 4\ Music\ Library $TUNESHARE/iTunes\ 4\ Music\ Library
    cp $GUESTLIB/iTunes\ Music\ Library.xml $TUNESHARE/iTunes\ Music\ Library.xml
  fi
  if [ $ROBLIB/iTunes\ 4\ Music\ Library -nt $TUNESHARE/iTunes\ 4\ Music\ Library ]; then
    cp $ROBLIB/iTunes\ 4\ Music\ Library $TUNESHARE/iTunes\ 4\ Music\ Library
    cp $ROBLIB/iTunes\ Music\ Library.xml $TUNESHARE/iTunes\ Music\ Library.xml
  fi
fi

exit 0

chmod to give them their “x” bits and then add as a LoginHook and a LogoutHook (respectively) via:

$ sudo defaults write com.apple.loginwindow LoginHook /Library/Scripts/synctunesin.sh
$ sudo defaults write com.apple.loginwindow LogoutHook /Library/Scripts/synctunesout.sh

So in theory, these should run when a user logs in and logs out (respectively) effectively synchronizing the iTunes Library files. I know the scripts work because running them manually from the command line seems to sync things up. But they do not appear to be executing (or executing properly?) as Login/outHooks despite the fact that they were successfully added:

rob@Malkovich $ sudo defaults read com.apple.loginwindow
{
    LoginHook = "/Library/Scripts/synctunesin.sh"; 
    LogoutHook = "/Library/Scripts/synctunesout.sh"; 
}

Thoughts? Comments? Suggestions? Alternatives?

About Rob Friesel

Software engineer by day, science fiction writer by night. Author of The PhantomJS Cookbook and a short story in Please Do Not Remove. View all posts by Rob Friesel →

7 Responses to synctunes

Anonymous says:

“exit 0” may not exist or
code may not be referenced at all, look to see if execution is being bypassed by any preceding code.

found_drama says:

re: “-m”

it’s not working b/c when run via “sudo” in the Terminal, it syncs the iTunes libraries of every user ref’d in the scripts. however, logging in as a given user does not seems to update playcounts or new tracks in the library etc. (in other words, it’s not copying across the expected files.)

found_drama says:

that’s sort of the trick…

the script runs as root after they’ve entered their password but before the OS X desktop loads

when i was testing the script manually, the first problem I encountered was that these users could not load iTunes b/c of permissions problems on the individual library files– a couple of “chown” and “chmod” commands later, this was sussed out though

and running the scripts manually w/ sudo on the terminal doesn’t change the ownership so i don’t think that’s it either

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*