Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kch
Created November 29, 2012 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kch/4170764 to your computer and use it in GitHub Desktop.
Save kch/4170764 to your computer and use it in GitHub Desktop.
#!/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 = ARGV.map { |s| Pathname.new(s).realpath.to_s }
itunes = app('iTunes')
name = "jwz-#{Time.now.strftime("%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 = paths.map { |path| library[path] }.compact
tracks.each { |track| itunes.duplicate(track, :to => playlist) }
@kch
Copy link
Author

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