iTunes Library lock, backup unchanged

Dear scripters,

I’m working on a project that envolves museums offering audiotours on a mac in the museum. Even with a good instuction people seem to be able to delete audio-files from the iTunes Library. What i would like to ask is a script that back-ups the whole user/music/itunes folder when itunes starts at the beginning of the day and deletes the possibly changed file at closing of itunes and replaces it with the back-up.

Or simply lock the file so people can download audiofiles to there mp3 player but cannot delete the files

i really have no idea where to start, i hope someone will help

thanks,

Jeffrey

Jeffrey:

I spent some time playing with iTunes today and I think this will work for you. You can use the Finder to get to the folder(s) that contain the actual audio files you are concerned about, and change the permissions to Read Only for that folder. (I tried doing this with the main iTunes folder, and it did not work. I had to actually work at the lowest level folder that contained the file tracks.) Now, you can still delete the tracks from iTunes, but the files will still be there, and can be easily retrieved back to the iTunes database. This script represents what I used for experimentation:


set Astral_folder to (path to music folder as Unicode text) & "iTunes:iTunes Music:Astral Vibes:Rock Goes Meditation (Rock Legends For Inner Silence)"

tell application "Finder" to set z to every file of folder Astral_folder

tell application "iTunes"
	repeat with zz in z
		try
			add (zz as alias)
		end try
	end repeat
end tell

To test it out, I went to the folder in question (set Astral_folder to (path to music folder as Unicode text) & “iTunes:iTunes Music:Astral Vibes:Rock Goes Meditation (Rock Legends For Inner Silence)”, which represents an entire album) in the Finder, set the permissions for that folder to Read Only, and then went to iTunes and deleted all the tracks from that album. They subsequently disappeared from my iTunes library. When I ran the above script, they magically re-appeared. Running the script with all (or some) of the tracks already present made no difference, that is, extra copies were NOT generated in iTunes. Deletion from the iTunes library did, however, also delete all the Play Count, Rating, Last Played, etc., etc. data from the track information in iTunes.

So, what you could do, is to make sure all the audio files you are concerned about have been consolidated into a single folder, set the permissions for that folder to Read Only, and plug that folder’s location into the script above. You could even have that script run every hour or so if you want to pick up anything that someone deleted, or just run it every evening.

Hope this helps,

Hi Jeffrey,

for this professional purpose I’d recommend to (let) write an iTunes based AppleScript Studio app,
which controls iTunes on the one hand and the user on the other.
It could have a small interface to browse and download the files (while iTunes works faceless or hidden in the background)
and the computer could run in a managed user account to avoid “unexpected user behavior”.

i want to thank both of you, the script is working and it help me atleast for now, ofcourse you are right Stefan, we need a more professional tool. But how do i come in contact with people who can be of help?

By the way i got it working with more maps by just adding them to the script like this, or am i thinking to simple here and can it be done wit less words?:


set Astral_folder to (path to music folder as Unicode text) & "iTunes:iTunes Music:Teylers Museum:Tweede schilderijen zaal"

tell application "Finder" to set z to every file of folder Astral_folder

tell application "iTunes"
	repeat with zz in z
		try
			add (zz as alias)
		end try
	end repeat
end tell
set Astral_folder to (path to music folder as Unicode text) & "iTunes:iTunes Music:Teylers Museum:Tweede fossielenzaal"

tell application "Finder" to set z to every file of folder Astral_folder

tell application "iTunes"
	repeat with zz in z
		try
			add (zz as alias)
		end try
	end repeat
end tell
set Astral_folder to (path to music folder as Unicode text) & "iTunes:iTunes Music:Teylers Museum:Ovale zaal"

tell application "Finder" to set z to every file of folder Astral_folder

tell application "iTunes"
	repeat with zz in z
		try
			add (zz as alias)
		end try
	end repeat
end tell

set Astral_folder to (path to music folder as Unicode text) & "iTunes:iTunes Music:Teylers Museum:Introductie museum en collectiegebieden"

tell application "Finder" to set z to every file of folder Astral_folder

tell application "iTunes"
	repeat with zz in z
		try
			add (zz as alias)
		end try
	end repeat
end tell
set Astral_folder to (path to music folder as Unicode text) & "iTunes:iTunes Music:Teylers Museum:Instrumentenzaal"

tell application "Finder" to set z to every file of folder Astral_folder

tell application "iTunes"
	repeat with zz in z
		try
			add (zz as alias)
		end try
	end repeat
end tell
set Astral_folder to (path to music folder as Unicode text) & "iTunes:iTunes Music:Teylers Museum:Eerste schilderijen zaal"

tell application "Finder" to set z to every file of folder Astral_folder

tell application "iTunes"
	repeat with zz in z
		try
			add (zz as alias)
		end try
	end repeat
end tell
set Astral_folder to (path to music folder as Unicode text) & "iTunes:iTunes Music:Teylers Museum:Eerste fossielenzaal"

tell application "Finder" to set z to every file of folder Astral_folder

tell application "iTunes"
	repeat with zz in z
		try
			add (zz as alias)
		end try
	end repeat
end tell

Here’s a shorter script for you. It should work as-is but in the future to make changes just modify the music_folders variable.

set music_folder_path to (path to music folder as Unicode text) & "iTunes:iTunes Music:Teylers Museum:"
set music_folders to {"Tweede schilderijen zaal", "Tweede fossielenzaal", "Ovale zaal", "Introductie museum en collectiegebieden", "Instrumentenzaal", "Eerste schilderijen zaal", "Eerste fossielenzaal"}

repeat with i from 1 to (count of music_folders)
	set this_folder to music_folder_path & (item i of music_folders)
	tell application "Finder" to set z to every file of folder this_folder
	
	tell application "iTunes"
		repeat with zz in z
			try
				add (zz as alias)
			end try
		end repeat
	end tell
end repeat

Here’s my thought about protecting your music from being deleted from the hard drive. You can create a disk image and copy all of your music to that. If you make your disk image “read only” then nothing can be deleted from it. iTunes can use this read-only disk image, so although users can delete the songs from itunes they can’t delete the actual music… and the above script can restore the itunes library every day to a pristine state.