Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > AppleScript Help Needed: Delete Watched TV Shows in iTunes

AppleScript Help Needed: Delete Watched TV Shows in iTunes
Thread Tools
AustinMatherne
Fresh-Faced Recruit
Join Date: Feb 2010
Location: Stamford, Connecticut, USA
Status: Offline
Reply With Quote
Feb 16, 2010, 03:30 PM
 
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
     
AustinMatherne  (op)
Fresh-Faced Recruit
Join Date: Feb 2010
Location: Stamford, Connecticut, USA
Status: Offline
Reply With Quote
Feb 16, 2010, 09:09 PM
 
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
     
RIRedinPA
Senior User
Join Date: Apr 2005
Status: Offline
Reply With Quote
Feb 17, 2010, 02:04 PM
 
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
Take It Outside!

Mid Atlantic Outdoors
     
BLAZE_MkIV
Professional Poster
Join Date: Feb 2000
Location: Nashua NH, USA
Status: Offline
Reply With Quote
Feb 17, 2010, 04:34 PM
 
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 Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 10:39 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,