Skip to content

Instantly share code, notes, and snippets.

@pjhyett
Created November 28, 2008 01:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save pjhyett/29877 to your computer and use it in GitHub Desktop.
Save pjhyett/29877 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/macruby
##
# Remove any duplicate tracks in iTunes
# PJ Hyett was here 11/2008
framework "Cocoa"
framework "ScriptingBridge"
itunes = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
finder = SBApplication.applicationWithBundleIdentifier("com.apple.Finder")
dups = []
seen = Hash.new { |hash, key| hash[key] = true; false }
itunes.sources.first.userPlaylists.first.fileTracks.each do |track|
if seen[track.name] && track.location.absoluteString =~ /%20[12]\.m4[ap]$/
dups << track
end
end
dups.each do |track|
finder.items.objectAtLocation(track.location).delete
end
# Uncomment the following lines if you want to immediately empty the trash
#finder.trash.warnsBeforeEmptying = false
#finder.trash.emptySecurity(false)
# then run this applescript to remove dead tracks from playlist
# http://dougscripts.com/itunes/scripts/ss.php?sp=removedeadsuper
# I'd would like to figure out the ScriptingBridge equivalent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment