Skip to content

Instantly share code, notes, and snippets.

@gunn
Created March 1, 2011 01:14
Show Gist options
  • Save gunn/848409 to your computer and use it in GitHub Desktop.
Save gunn/848409 to your computer and use it in GitHub Desktop.
Play any track visible to itunes - local or in shared library with macruby.
#! /bin/env macruby
framework 'Foundation'
framework 'ScriptingBridge'
itunes = SBApplication.applicationWithBundleIdentifier("com.apple.itunes")
itunes.run
itunes.sources.each_with_index do |source, lib_index|
library = source.libraryPlaylists.first
if library
puts "[#{lib_index}] #{source.name}:"
library.tracks.first(10).each_with_index do |track, track_index|
puts "\t[#{track_index}] #{track.name} (#{track.time})"
end
puts "\n"
end
end
while true
begin
puts "Please pick a library (number 0-#{itunes.sources.size-1})"
library = itunes.sources.to_a[gets.to_i].libraryPlaylists.first
rescue
retry
end
begin
puts "Please pick a track (number 0-#{library.tracks.size-1})"
track = library.tracks.to_a[gets.to_i]
track.playOnce(true)
puts "playing #{track.name} (#{track.time})"
rescue
retry
end
puts "\n\n*press any key for options*"
gets
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment