Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

darkmaster87

macrumors newbie
Original poster
May 8, 2010
5
0
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

Moderator
Staff member
Aug 9, 2009
10,758
8,451
A sea of green
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-

macrumors P6
Jun 19, 2009
16,793
51
Where bunnies are welcome.
This will find the dupes and mark them. Pretty simple to delete them if you wanted.

PHP:
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

macrumors newbie
Original poster
May 8, 2010
5
0
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

macrumors Core
Jul 24, 2006
19,260
36
The Ivory Tower (I'm not coming down)
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 has a number of duplicate deletion scripts.
 

Attachments

  • Picture 2.png
    Picture 2.png
    76 KB · Views: 120

-aggie-

macrumors P6
Jun 19, 2009
16,793
51
Where bunnies are welcome.
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 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

macrumors newbie
Original poster
May 8, 2010
5
0
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-

macrumors P6
Jun 19, 2009
16,793
51
Where bunnies are welcome.
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:

PHP:
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

macrumors newbie
Original poster
May 8, 2010
5
0
Something like this:

PHP:
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-

macrumors P6
Jun 19, 2009
16,793
51
Where bunnies are welcome.
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

macrumors newbie
Original poster
May 8, 2010
5
0
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.