pjhyett (owner)

Forks

Revisions

gist: 29877 Download_button fork
public
Public Clone URL: git://gist.github.com/29877.git
Embed All Files: show embed
dedup.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/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