创建iTunes播放列表并在MacRuby中添加曲目

时间:2012-08-28 09:50:39

标签: objective-c itunes macruby scripting-bridge

为什么此代码会导致播放列表为空?如何将该曲目录制到播放列表中?

#!/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

(如果你知道一种避免在使用之前需要插入播放列表的方法,那也很有用。)

1 个答案:

答案 0 :(得分:1)

Eureka,发现它(感谢这篇旧帖子 - 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)