View RSS Feed

The Ill-Tempered Audiophool

Write-protect your iTunes library to avoid accidental deletion or damage

Rate this Entry
Here are two AppleScripts that turn write-protection on and off for your music library. If you want to add or edit stuff, run the script ResetWriteProtectMusic. If you want to protect your music files from accidental alteration or deletion, run the script WriteProtectMusic. These can be placed in the user's ~/Library/iTunes/Scripts directory, and they appear in the iTunes script menu item (here as the bottom two entries):

Name:  menu_iTunes_Scripts.png
Views: 8071
Size:  27.0 KB

The AppleScripts (Updated for 10.11 and iTunes 12.3, should be back-compatible):

PutThisInLibraryItunesScripts.zip

The scripts assume a normal iTunes-organized music library, but you can alter them easily enough if your situation is non-standard.

It is designed to "just work" for a standard iTunes library, regardless of where you have it located.

Here is how this is discovered:

The first line contains a line of unix code (embedded as an Osascript) that looks like this:

Code:
defaults read ~/Library/Preferences/com.apple.iApps.plist iTunesRecentDatabases | grep file | perl -p -e 's|file://localhost||g' | perl -p -e 's|iTunes%20Music%20Library.xml||g' | perl -p -e 's|iTunes%20Library.xml||g' | perl -p -e 's|    \"||g' | perl -p -e 's|\"||g'
It reads the iTunes library XML file to find where you keep your music. On my iMac, it returns this:

Code:
/Users/wgscott/Music/iTunes/
and on my mac mini, it returns this:

Code:
/Volumes/Media/iTunes/
Attached Thumbnails Attached Files

Updated 10-17-2015 at 12:43 AM by wgscott

Categories
tweaks , computer

Comments

  1. Danold's Avatar
    Thanks for this script. However, when I run the WriteProtectMusic script I get:

    chmod: /Volumes/MMMM/XYZ/Music/iTunes/iTunes Media/Music: No such file or directory

    while in reality my iTunes Music Library.xml addresses my music at : File://localhost/Volumes/MMMM/XYZ/Music/iTunes/iTunes%20Music/

    Where does the script get its (wrong) information from?
  2. wgscott's Avatar
    ... [deleted]

    I'll try to figure out why. I have that directory as well on all my computers, but it is always empty. Do you have anything apart from music in your iTunes library?

    In any case, I will revise the script to do some sort of conditional test to determine which directory is active (or maybe just make a second script).
  3. Danold's Avatar
    Quote Originally Posted by wgscott
    ... [deleted]

    I'll try to figure out why. I have that directory as well on all my computers, but it is always empty. Do you have anything apart from music in your iTunes library?

    In any case, I will revise the script to do some sort of conditional test to determine which directory is active (or maybe just make a second script).
    Hi Scott: I figured it out today. In the script I changed the line

    set MusicPath to PathHead & "iTunes\\ Media/Music"

    to


    set MusicPath to PathHead & "iTunes\\ Music"

    and that was it. Thanks anyway.
  4. wgscott's Avatar
    The revised version at the link above now looks for both, and modifies either or both when present.

    I was going to ask you to test it to make sure it fixed your problem, but (with the same change I made) it looks like it has.

    Thanks.

    Bill
  5. Danold's Avatar
    The new scripts work just fine. Great.
  6. Danold's Avatar
    OK, finally: It doesn't work at all.

    I write-protected the music files (they are all .m4a), opened them in e.g. Amadeus and could change anything I wanted, music, metadata, whatever. In other words it doesn't seem to be possible to protect music files from being changed by other processes. The only effect was that I couldn't change any metadata from within iTunes.
  7. AudioDoctor's Avatar
    I just tried this in iTunes 12.3.0.44 and got the CHMOD no such file or directory error as well.
  8. AudioDoctor's Avatar
    to help others who know just enough to screw everything up like me...

    The iTunes script folder is in "Macintosh HD/Library/iTunes/scripts" NOT "User/library/iTunes/~"

    When put in the proper place, it works just fine... Thanks Bill.