Last Updated: February 25, 2016
· kogakure

Sync iTunes via rsync to a NAS when it’s content changes

This script watches the iTunes folder for changes. As soon as something is changed iTunes will update the xml file. This change is watched by this launchd service. It starts rsync which syncs all changed/new music to the network drive.

Launchd services of the user live in ~/Library/LaunchAgents. They have to be loaded with launchctl load -w ~/Library/LaunchAgent/scriptname.plist. I recommend installing the "lunchy" gem, which makes this more easy.

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <string>Sync the iTunes Library with the Sonos network attached storage as soon as iTunes changes</string>
Say Thanks

2 Responses
Add your response



I am really interrested in getting this to work, but I lack some programming skills on MAC.

How do I get this to run ?
How do I get the script to automount my NAS drive ?

over 1 year ago ·

This isn’t really programming, just using the shell. You need some basic skills, like how to navigate the terminal, creating files, editing files. There are some GUI-Tools like Lingon (http://www.peterborgapps.com/lingon/) to create LaunchDeamons, but you need at least to know how to execute a command. The file above is just a pure text file in the XML format. The ending is .plist, an Apple format for PropertyLists.

You could just execute the command in this file manually in the Terminal. All the deamon does is starting a service which triggers this script every time something in iTunes changes (there is a settings file in this folder, which gets written, when something changes):

/usr/bin/rsync --recursive --ignore-existing --compress --delete /Users/your-user-name/Music/iTunes/ /Volumes/your-external-hd-name/iTunes/

This uses rsync (a unix tool for syncing files), coping all folders recursive, only new ones, compressing it during transfer for speed and deleting files/folders not existing any more. It copies your iTunes library folder to the external harddrive to a folder "iTunes".

For automounting you could use AppleScript, just google and you will find a lot of scripts on StackOverflow or somewhere else.

over 1 year ago ·
Filed Under