iTunes deletion?

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

iTunes deletion? Tue Aug 07, 2012 11:38 am • by Ynot
I'm trying to put together a rule that looks at a particular folder in iTunes to see whether a file exists and has been added more than a day ago and, if so, delete it. I don't have a problem with the basic rule, but I'm wondering whether anyone has a good applescript to do the deletion (rather than simply deleting the file, which won't let iTunes know to remove the file from its list of tracks).

(This is designed to remove voicemails after I listen to them.)

Thanks,
Tony
Ynot
 
Posts: 4
Joined: Tue Jul 17, 2012 10:47 pm

Re: iTunes deletion? Tue Aug 07, 2012 1:02 pm • by a_freyer
This is an applescript that should work for your situation:

Code: Select all
set removeTotal to 0
tell application "iTunes"
   set mainLibrary to library playlist 1
   set totalTracks to count of file tracks of mainLibrary
   with timeout of 10 seconds
      repeat with t from totalTracks to 1 by -1
         try
            set this_track to file track t of mainLibrary
            if this_track's location is missing value and this_track's duration is missing value then
               removeTotal = removeTotal + 1
               delete this_track
            end if
         end try
      end repeat
   end timeout
end tell


Essentially, this script checks for anything in the iTunes library (books, music, movies, etc.) whose duration element is null. Even for books, the duration element returns a zero value if the file is present.

Notice the removeTotal variable is currently not used. You could export this as a token to Hazel in order to send an alert that "19 items have been removed from the iTunes library."

Hope this helps!


EDIT - To clarify, this will remove a file from the iTunes library database only. You should physically delete the file from the iTunes directories before this script is run.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: iTunes deletion? Wed Aug 08, 2012 11:32 am • by Ynot
Thanks! Does this have any quirky side effects if all of my songs are on iTunes Match (i.e., generally not on my computer's hard drive)?
Ynot
 
Posts: 4
Joined: Tue Jul 17, 2012 10:47 pm

Re: iTunes deletion? Wed Aug 08, 2012 11:35 am • by a_freyer
It shouldn't, but I haven't tested since I don't use iTunes Match.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado


Return to Support