PDA

View Full Version : How to make an applescript to delete iTunes duplicates?




darkmaster87
May 8, 2010, 03:51 PM
I'm trying to make a program to find and delete duplicate files in iTunes but I don't know the code to delete files. Please help if you know a code that can delete half of the playlist showing the songs leaving only one copy of each song left.



chown33
May 8, 2010, 04:42 PM
Google keywords: applescript to show iTunes duplicates

Before starting to develop something, the first step is to see if it already exists. If it exists and does exactly what you want, then problem solved with no additional development needed. If it's only close to what you want, then you at least have a working example to look at.

-aggie-
May 8, 2010, 04:48 PM
This will find the dupes and mark them. Pretty simple to delete them if you wanted.

tell application "iPhoto"
set curPhotos to selection

set theCount to 0
repeat with thisPhoto in curPhotos
set theCount to theCount + 1
get theCount
if theCount = 1 then
set lastPhoto to thisPhoto
else
if (width of thisPhoto = width of lastPhoto) and (height of thisPhoto = height of lastPhoto) and (date of thisPhoto = date of lastPhoto) then
set thisSize to size of (info for (image path of thisPhoto as POSIX file))
set lastSize to size of (info for (image path of lastPhoto as POSIX file))

if thisSize ≥ lastSize then
set comment of thisPhoto to "duplicate"
else
set comment of lastPhoto to "duplicate"
end if

end if
set lastPhoto to thisPhoto

end if

end repeat

beep
beep
display alert "All duplicate photos have been marked DUPLICATE"
end tell

darkmaster87
May 8, 2010, 04:49 PM
Google keywords: applescript to show iTunes duplicates

Before starting to develop something, the first step is to see if it already exists. If it exists and does exactly what you want, then problem solved with no additional development needed. If it's only close to what you want, then you at least have a working example to look at.

I have looked for an existing program that does this but none of them are free and the demos won't work on my computer for some reason.

miles01110
May 8, 2010, 04:50 PM
I have looked for an existing program that does this but none of them are free and the demos won't work on my computer for some reason.

I assume you also know about the "Display Duplicates" feature built into iTunes? Is that not what you're looking for? See attached image.

This will find the dupes and mark them. Pretty simple to delete them if you wanted.


Well... kind of. This is for photos. For iTunes duplicates dougscripts (http://dougscripts.com/itunes/) has a number of duplicate deletion scripts.

-aggie-
May 8, 2010, 04:58 PM
I assume you also know about the "Display Duplicates" feature built into iTunes? Is that not what you're looking for? See attached image.



Well... kind of. This is for photos. For iTunes duplicates dougscripts (http://dougscripts.com/itunes/) has a number of duplicate deletion scripts.

Ugh! Was going through my Applescripts and forgot this was for iTunes. Yes, dougscripts has that. However, he may not be able to see the source code.

Edit: Looks like he'll only find Dupin, which is now a paid Applescript.

darkmaster87
May 8, 2010, 05:03 PM
I assume you also know about the "Display Duplicates" feature built into iTunes? Is that not what you're looking for? See attached image.
Yes, I know that iTunes has the "Display Duplicates" feature built in. My code uses that to only show duplicates so that the following code only affects duplicated files and not my entire library. The problem is deleting the files after I have excluded the non-duplicates, which I don't know the code to do.

-aggie-
May 8, 2010, 05:24 PM
Yes, I know that iTunes has the "Display Duplicates" feature built in. My code uses that to only show duplicates so that the following code only affects duplicated files and not my entire library. The problem is deleting the files after I have excluded the non-duplicates, which I don't know the code to do.

Something like this:


repeat with theFile in the result
set itemPath to the (theFile as text)
do shell script "rm -r " & (quoted form of POSIX path of itemPath)
end repeat

darkmaster87
May 8, 2010, 05:31 PM
Something like this:


repeat with theFile in the result
set itemPath to the (theFile as text)
do shell script "rm -r " & (quoted form of POSIX path of itemPath)
end repeat

I added it to my code but it didn't do anything. Does it require a separate file to work or something?

-aggie-
May 8, 2010, 05:34 PM
I added it to my code but it didn't do anything. Does it require a separate file to work or something?

Well, of course you have to supply the repeat with thefile from the result. I figured you'd got that far, so you had some "results" which you could then go through to get "thefile" to be deleted. Do you know how to read Applescript?? :confused:

darkmaster87
May 8, 2010, 05:47 PM
Well, of course you have to supply the repeat with thefile from the result. I figured you'd got that far, so you had some "results" which you could then go through to get "thefile" to be deleted. Do you know how to read Applescript?? :confused:
I can't read it that well, most of the time I have to go to the dictionary and files that are similar to what I am making to find codes