Adding playlists to iTunes with SB

  • Hi,

    I am trying to create a playlist and add it to iTunes using scriptig
    bridge. Based on Apples documentation I do the following:

    iTunesApplication *iTunes = [SBApplication
    applicationWithBundleIdentifier:@"com.apple.iTunes"];
    SBElementArray *sources = [iTunes sources];
    iTunesSource *librarySource = [sources objectWithName:@"Library"];
    SBElementArray *myUserPlaylists = [librarySource userPlaylists];
    [iTunes activate];

    NSNumber *vis = [NSNumber numberWithBool:TRUE];
    NSDictionary *propes = [NSDictionary
    dictionaryWithObjectsAndKeys:@"ZZZ", @"name", vis, @"visible", nil];
    iTunesPlaylist *myPlaylist = [[[iTunes
    classForScriptingClass:@"playlist"] alloc] initWithDictionary:propes];

    //NSLog(@"Custom Playlist: %@", [myPlaylist name]);
    [myUserPlaylists addObject:myPlaylist];

    However, the application goes into debug mode and I am having
    difficulties knowing what is going wrong. Am I initializing the custom
    playlist with the wrong or to few parameters? Later on I would like to
    add a couple of tracks to my playlist.

    Any help is highly appreciated

    Ed
  • Eddy Hatcher wrote:

    > I am trying to create a playlist and add it to iTunes using scriptig
    > bridge. Based on Apples documentation I do the following:
    >
    > NSDictionary *propes = [NSDictionary
    > dictionaryWithObjectsAndKeys:@"ZZZ", @"name", vis, @"visible", nil];
    > iTunesPlaylist *myPlaylist = [[[iTunes
    > classForScriptingClass:@"playlist"] alloc] initWithDictionary:propes];

    s/initWithDictionary:/initWithProperties:/

    > [myUserPlaylists addObject:myPlaylist];

    Be aware that -[SBElementArray addObject:] is borked on iTunes and
    various other applications; see the following thread for details:

    http://lists.apple.com/archives/Applescript-implementors/2007/Nov/threads.h
    tml#00034


    One possible workaround is to use -insertObject:atIndex:, but that
    only works if there's already one or more elements present. Another
    possibility is to forgo SB's weird object creation process and
    construct your own 'make' command using -[SBObject
    sendEvent:id:parameters:].

    Another option would be to use objc-appscript:

    http://appscript.sourceforge.net/objc-appscript.html

    which speaks Apple events the same way that AppleScript and the Apple
    Event Manager do, allowing you to compose a 'make' command with the
    correct parameters without having to resort to raw AE codes and stuff.
    While objc-appscript isn't entirely finished (working on it), it's
    already more functional and provides better application compatibility
    than Scripting Bridge.

    HTH

    has
    --
    http://appscript.sourceforge.net
    http://rb-appscript.rubyforge.org
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today