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.
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
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.
This will find the dupes and mark them. Pretty simple to delete them if you wanted.
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.
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.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.
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?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?
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 codesWell, 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??