iTunes – sync music folder (script)

Sync the music folder in iTunes (my script):


I wanted that iTunes automatically syncs my music folder onto my iPhone.

First I mount the centrally stored samba share with my music.

After that the music folder is getting synced to my desktop.

Then all of the music in iTunes is getting deleted.


You have to manually select every song in iTunes (CMD + A) and remove them before you run the script.

If you don’t do this iTunes will list the tracks two times, but recognizes that the old ones were deleted but they still stand in the library. I didn’t found a solution to delete them also (the „symlink“ in iTunes to the music files).


The last step is to press the sync button manually. iTunes will search your phone over wifi and synchronizes it automatically.

I don’t found a way to trigger this button via the command line.

My opinion: It is not fully automated, but this script saves me a lot of time.


echo "clear the music library"
mount_smbfs //guest:guest@ Download/
rsync -av --progress --delete --exclude="._*" Download/Media/Music/_music/ /Users/mathias/Desktop/_music/
rm -fr /Users/mathias/Music/iTunes/iTunes\ Media/Music/
cp -r /Users/mathias/Desktop/_music/ /Users/mathias/Music/iTunes/iTunes\ Media/Automatically\ Add\ to\ iTunes.localized/
echo "press the sync button in itunes"

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.