|
|
AppleScript Help Needed: Delete Watched TV Shows in iTunes
|
|
|
|
Fresh-Faced Recruit
Join Date: Feb 2010
Location: Stamford, Connecticut, USA
Status:
Offline
|
|
First off, I'm extremely new to AppleScripting, I've only read a few beginners guides and I'm just starting to understand how it all works. But you gotta start somewhere right?
What I'm trying to create is an AppleScript that will delete any watched TV Show from both the iTunes database and the physical video files. I figure that if I create a smart playlist in iTunes that pulls in every TV Show with a play count greater than 0 it should make deleting the shows a bit easer.
If anyone knows how to do this and could point me in the right direction, I would truly appreciate it.
Thanks,
|
~ Austin
|
|
|
|
|
|
|
|
Fresh-Faced Recruit
Join Date: Feb 2010
Location: Stamford, Connecticut, USA
Status:
Offline
|
|
I've got the script below which seems to work perfectly, but I'm stuck on adding an error check so that if it doesn't find anything to delete it won't display an error. If anyone knows how to do this, I'd truly appreciate the help.
Code:
tell application "iTunes"
set filesToDelete to location of (file tracks whose (video kind is TV show) and (unplayed is false))
delete (tracks whose (video kind is TV show) and (unplayed is false))
end tell
tell application "Finder"
repeat with theFile in filesToDelete
delete theFile
end repeat
end tell
Thanks,
|
~ Austin
|
|
|
|
|
|
|
|
Senior User
Join Date: Apr 2005
Status:
Offline
|
|
Hey Austin
You can always trap your errors and then write them out to a log, that way your script will continue to run but you will also be able to record whatever errors are generated. (Handy for debugging).
I modified your script but have not tested it:
set errfile to (path to desktop as string) & "iTunesErrorLog.txt"
set thedate to (current date) as text
my writeFile(errfile, thedate & return & return)
tell application "iTunes"
try
set filesToDelete to location of (file tracks whose (video kind is TV show) and (unplayed is false))
delete (tracks whose (video kind is TV show) and (unplayed is false))
on error errmsg
my writeFile(errfile, "Error in iTunes" & errmsg & return)
end try
end tell
tell application "Finder"
try
repeat with theFile in filesToDelete
delete theFile
end repeat
on error errmsg
my writeFile(errfile, "Error deleting the file in Finder" & errmsg & return)
end try
end tell
on writeFile(theFilePath, theContent)
set f to (open for access theFilePath with write permission)
write return & theContent to f starting at eof
close access f
end writeFile
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Feb 2000
Location: Nashua NH, USA
Status:
Offline
|
|
you need to check to see if there are any items in filesToDelete before you delete them.
it also looks like your deleting all the files not just the ones who have been watched.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|