1

Why does this code result in an empty playlist, and how can I get that track into the playlist?

#!/usr/local/bin/macruby
framework 'Cocoa'
framework 'ScriptingBridge'

load_bridge_support_file 'iTunes.bridgesupport'
iTunes = SBApplication.applicationWithBundleIdentifier 'com.apple.iTunes'

userPlaylists = iTunes.sources.objectWithName("Library").userPlaylists
userPlaylists << (ITunesUserPlaylist.alloc.initWithProperties Hash[{"name"=>"something unique"}])
playlist = userPlaylists.objectWithName("something unique")
iTunes.add [userPlaylists.objectWithName("Music").tracks[0]], to:playlist

(if you know a way to avoid needing to insert the playlist before using it, that'd be helpful too.)

Chris Adams
  • 1,008
  • 1
  • 11
  • 22

1 Answers1

1

Eureka, found it (thanks to this old post - http://www.exampler.com/mac-scripting/todays-tunes.rb)

playlist = ITunesUserPlaylist.alloc.initWithProperties ({"name"=>"something unique"})
$iTunes.sources.objectWithName("Library").playlists << playlist
track = $iTunes.sources.objectWithName("Library").userPlaylists.objectWithName("Music").tracks[0]
track.duplicateTo(playlist)
Chris Adams
  • 1,008
  • 1
  • 11
  • 22