Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env ruby
# encoding: UTF-8
require 'appscript'
require 'pathname'
include Appscript
### Usage:
# ./itunes-mk-playlist.rb \
# ~/"Music/iTunes/iTunes Media/Music/Atomine Elektrine/Zektor X/09 ...and Ever.mp3" \
# ~/"Music/iTunes/iTunes Media/Music/DarkDriveClinic/Noise in My Head/09 Angel of Malcontent.m4a" \
# ~/"Music/iTunes/iTunes Media/Music/Rome/Die Aesthetik Der Herrschaftsfreiheit - Band 1/02 The Angry Brigade.mp3" \
# ~/"Music/iTunes/iTunes Media/Music/The Submarines/Love Notes_Letter Bombs/10 Anymore.mp3"
paths = { |s| }
itunes = app('iTunes')
name = "jwz-#{"%Y-%m-%d %H:%M")}"
playlist = itunes.make(:new => :user_playlist, :with_properties => {:name => name})
library = itunes.tracks.get.inject({}) { |h, t| h[t.location.get.to_s] = t; h }
tracks = { |path| library[path] }.compact
tracks.each { |track| itunes.duplicate(track, :to => playlist) }

This comment has been minimized.

Copy link
Owner Author

@kch kch commented Nov 29, 2012

You'll want to gem install rb-appscript first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.