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"> <dict> <key>Label</key> <string>de.coolshit.SyncITunesToSonos</string> <key>ServiceDescription</key> <string>Sync the iTunes Library with the Sonos network attached storage as soon as iTunes changes</string> <key>LowPriorityIO</key> <true/> <key>ProgramArguments</key> <array> <string>/usr/bin/rsync</string> <string>--recursive</string> <string>--ignore-existing</string> <string>--compress</string> <string>--delete</string> <string>/Users/*USER*/Music/iTunes/</string> <string>/Volumes/*Sonos-NAS*/iTunes/</string> </array> <key>WatchPaths</key> <array> <string>/Users/*USER*/Music/iTunes/</string> </array> </dict> </plist>