Skip to content

Instantly share code, notes, and snippets.

@wesrog
Created November 10, 2009 16:55
Show Gist options
  • Save wesrog/231031 to your computer and use it in GitHub Desktop.
Save wesrog/231031 to your computer and use it in GitHub Desktop.
Sort iTunes groupings
def w(t); t.grouping = s(t) unless s?(t); end
def s?(t); t.grouping.to_s == s(t); end
def s(t); t.grouping.to_s.split(', ').sort.join(', '); end
require 'osx/cocoa'
OSX.require_framework 'ScriptingBridge'
a = OSX::SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
l = a.sources.first.playlists.detect { |p| p.name == 'Library' }
l.tracks.each_with_index { |t,i| print "\r\e[0KProcessing: #{i}/#{l.tracks.size}"; w(t); $stdout.flush; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment