1

I'm trying to populate an NSPopUpButton with an array of ITunesPlaylist objects. I got the NSArrayController bind to NSPopUpButton

app = SBApplication.applicationWithBundleIdentifier("com.apple.iTunes")
playlists = app.sources.objectWithName("Library").userPlaylists

myArrayController.setContent playlists

All the playlists will appear in the NSPopUpButton but they all have names with

<ITunesUserPlaylist:0x4018a5000: iTunesUserPlaylist 0 of iTunes Source "Library" of Application "iTunes" (51822)>

What I want to do is bind ITunesPlaylist.name to the content value of the NSPopUpButton, but I can't seem to get it to work.

There also seem to be very little documentation on class definitions of objects returned by Scripting Bridge API calls (e.g. ITunesPlaylist, ITunesTrack).

Can someone give me some pointers? Ultimately I'd like to make an drop-down menu that shows the user's iTunes playlist in hierarchal form.

goofrider
  • 231
  • 1
  • 8

2 Answers2

1

Are you sure you properly set the bindings with the proper key path? Did you also load the bridgesupport file? I verified the ITunesUserPlaylist class and it should be KVC compliant.

playlists.first.valueForKey('name')

Returns the proper name.

If you share a bit more code, I could potentially look into the issue.

Also, here are some methods available on your playlist:

Class: iTunesPlaylist
Properties:
duration (the total length of all songs (in seconds))
name (the name of the playlist)
parent (folder which contains this playlist (if any))
shuffle (play the songs in this playlist in random order?)
size (the total size of all songs (in bytes))
songRepeat (playback repeat mode)
specialKind (special playlist kind)
time (the length of all songs in MM:SS format)
visible (is this playlist visible in the Source list?)

Method: tracks
Returned: SBElementArray
----
Method: moveTo:(SBObject *)to
Returned: void
Move playlist(s) to a new location
----
Method: searchFor:(NSString *)for_ only:(iTunesESrA)only
Returned: iTunesTrack
search a playlist for tracks matching the search string. Identical to entering search text in the Search field in iTunes.

Class: iTunesUserPlaylist
Properties:
shared (is this playlist shared?)
smart (is this a Smart Playlist?)

Method: fileTracks
Returned: SBElementArray
----
Method: URLTracks
Returned: SBElementArray
----
Method: sharedTracks
Returned: SBElementArray
----
Matt Aimonetti
  • 1,112
  • 1
  • 10
  • 11
0

Thanks for your help. It turned out these were my problems:

  1. XCode 4 Interface Builder does not recognize the type "iTunesPlaylist" in the ArrayController's Class Name field unless I import "iTunes.h" to the project first, which I had to generate it:

    $ sdef /Applications/iTunes.app | sdp -fh --basename iTunes

  2. The Popup Button can then be binded to the the "name" of the arrangedObjects in ArrayController by setting "Modal Key Path" to "name" in the NSPopUpButton's content binding in XCode IBuilder, but "Raise for Not Application Keys" was checked by default so the app will crash at startup because the ArrayController was empty. I unchecked it and everything works fine

goofrider
  • 231
  • 1
  • 8
  • 1
    For further info about the header file and the doc, you can read this old blog post of mine: http://merbist.com/2010/01/17/controlling-itunes-with-macruby/ – Matt Aimonetti Mar 03 '12 at 04:58
  • Actually your post was one of the places I came across that explained the iTunes.h requirements. Great post!! – goofrider Mar 10 '12 at 12:14