Clear iTunes Library and rescan folder

Hi there!

I’ve got a question concerning my first AppleScript.
I need to clear my whole iTunes Library and rescan my network-music-drive.
And this should happen every night @ 3 A.M.
(So that I can let the Mac on when I want to rescan, otherwise I just turn it off)

Is it possible to script something like that?
Perhaps you can give me some usefull hints or snippets maybe, so I know how to begin my script?!

I really hope you can help me :smiley:

bye
zapp2me

How do you have iTunes set up? I assume you’ve got it set to a)not copy items into the iTunes folder and b)you’ve pointed iTunes’ preferences to some other folder (some folder that is being updated from an outside source).

That being said, it should be fairly straightforward (though I’m not going to wipe out MY iTunes to test it out :)):


tell application "Finder" to set myMusic to (path to home) & "Music" & "iTunes" & "iTunes Music"
tell application "iTunes"
	delete every track of library playlist
	add myMusic
end tell

But I’ll log out of my account and try it on a test account to be sure it works.

OK, I was a little off. Here’s what worked for me, but there’s one caveat (see below)


--set the variable myMusic to location of your folder that you need to rescan
set myMusic to "Pinky:Users:Shared Documents:Music"
tell application "iTunes"
	activate
	delete (every track of front window)
	--display a "done deleting" dialog here if you want to.
	add myMusic
end tell

I had mixed success with this. Sometimes it just didn’t want to delete the tracks, which might be a weirdness of my version of Mac OS X (I’m on Jaguar) or a glitch in the iTunes dictionary. But it does work.

Let me know what results you get.