How to make an applescript to delete iTunes duplicates?

Discussion in 'Mac Programming' started by darkmaster87, May 8, 2010.

  1. macrumors newbie

    Joined:
    May 8, 2010
    #1
    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.
     
  2. macrumors 603

    Joined:
    Aug 9, 2009
    #2
    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.
     
  3. macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #3
    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 lastPhotothen
                    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
     
  4. thread starter macrumors newbie

    Joined:
    May 8, 2010
    #4
    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.
     
  5. macrumors Core

    miles01110

    Joined:
    Jul 24, 2006
    Location:
    The Ivory Tower (I'm not coming down)
    #5
    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.
     

    Attached Files:

  6. macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #6
    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.
     
  7. thread starter macrumors newbie

    Joined:
    May 8, 2010
    #7
    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.
     
  8. macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #8
    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
     
  9. thread starter macrumors newbie

    Joined:
    May 8, 2010
    #9
    I added it to my code but it didn't do anything. Does it require a separate file to work or something?
     
  10. macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #10
    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:
     
  11. thread starter macrumors newbie

    Joined:
    May 8, 2010
    #11
    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
     

Share This Page