Jump to content
  • entries
    47
  • comments
    385
  • views
    8169

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


wgscott

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):

 

<p><a href="https://audiophilestyle.com/uploads/monthly_2014_07/menu_iTunes_Scripts.png.2ca9ab456e125a704513078a620a72b7.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28275" src="https://audiophilestyle.com/uploads/monthly_2014_07/menu_iTunes_Scripts.png.2ca9ab456e125a704513078a620a72b7.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>

 

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

 

[ATTACH]21546[/ATTACH]

 

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:

 

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:

 

/Users/wgscott/Music/iTunes/

 

and on my mac mini, it returns this:

 

/Volumes/Media/iTunes/

<p><a href="https://audiophilestyle.com/uploads/monthly_2014_07/Scripts_7_21_2014_150_zip.7a47d2e5f4ffd7f5bc2819f5dbab584a" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28276" src="https://audiophilestyle.com/uploads/monthly_2014_07/Scripts_7_21_2014_150_zip.7a47d2e5f4ffd7f5bc2819f5dbab584a" class="ipsImage ipsImage_thumbnailed" alt=""></a></p><p><a href="https://audiophilestyle.com/uploads/monthly_2014_07/menu_iTunes_Scripts.png.dac64611e7d172b7c96964b624bbee92.png" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28525" src="https://audiophilestyle.com/uploads/monthly_2014_07/menu_iTunes_Scripts.png.dac64611e7d172b7c96964b624bbee92.png" class="ipsImage ipsImage_thumbnailed" alt=""></a></p><p><a href="https://audiophilestyle.com/uploads/monthly_2014_07/Scripts_7_21_2014_150_zip.391cdbd313844fce01a19a92c6fcb21e" class="ipsAttachLink ipsAttachLink_image"><img data-fileid="28526" src="https://audiophilestyle.com/uploads/monthly_2014_07/Scripts_7_21_2014_150_zip.391cdbd313844fce01a19a92c6fcb21e" class="ipsImage ipsImage_thumbnailed" alt=""></a></p>

8 Comments


Recommended Comments

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?

Link to comment

... [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).

Link to comment
... [deleted]

 

I'll try to figure out why. I have that directory as well on all my computers' date=' 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).[/quote']

 

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.

Link to comment

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

Link to comment

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.

Link to comment

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.

Link to comment



×
×
  • Create New...