1

为什么这段代码会导致播放列表为空,我怎样才能将该曲目放入播放列表?

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

(如果您知道一种避免在使用前插入播放列表的方法,那也会很有帮助。)

4

1 回答 1

1

尤里卡,找到了(感谢这篇旧帖子 - 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)
于 2012-08-28T10:20:58.547 回答