Trying to get my head around an NSGenericException/Apple Event error

  • I cannot reproduce this problem myself, but I've been getting a lot of bug
    reports lately that all boils down to the same thing: an
    NSGenericException raised by an Apple Event returning an -1708 error. The
    Apple event is sent to iTunes using ScriptingBridge. According to the docs,
    -1708 means "<reference> doesn't understand the <commandName> message". Yet
    I don't think there's anything wrong with the code, it works fine over here
    and for some 90% of the end users. (I'm catching these exceptions, but since
    I need the result of those Apple events it doesn't help much...)
    A typical exception looks like this: Apple event returned an error.  Event =
    'hook'\'Srch'{ '----':'obj '{ 'want':'cLiP', 'from':'obj '{ 'want':'cSrc',
    'from':'null'(), 'form':'indx', 'seld':1 }, 'form':'indx', 'seld':1 },
    'pTrm':'utxt'("Beck"), 'pAre':'kSrR' }

    (That 'from':'null'() thing looks a little suspicious...)

    The code that throws this exception is:

    track_array = (SBElementArray *)[libraryPlaylist searchFor:theArtist only :
    'kSrR']; //only artists

    (...where  libraryPlaylist = [[[[[iTunes sources ] objectAtIndex:0]
    libraryPlaylists] objectAtIndex:0] retain]  )

    Similar exceptions are thrown for other operations as well, for example when
    retrieving user playlists, so it's not just the search part causing
    problems.

    Any ideas? Could the problem be these users have multiple sources/library
    playlists in iTunes? If so, how do I find the main source/library playlist
    without explicitly asking the user for it?
  • On 22 Dec 2007, at 8:41 AM, <slasktrattenator...> wrote:

    > A typical exception looks like this: Apple event returned an error.
    > Event =
    > 'hook'\'Srch'{ '----':'obj '{ 'want':'cLiP', 'from':'obj
    > '{ 'want':'cSrc',
    > 'from':'null'(), 'form':'indx', 'seld':1 }, 'form':'indx', 'seld':1 },
    > 'pTrm':'utxt'("Beck"), 'pAre':'kSrR' }
    >
    > (That 'from':'null'() thing looks a little suspicious...)

    The null container in the Apple Event object model is the application
    itself.

    '----':'obj '    # Direct object is an object(1) such that...
        { 'want':'cLiP', 'from':'obj ' # (1)'s a library playlist from an
    object(2) such that
          { 'want':'cSrc', 'from':'null'(), # (2) is a source from the
    application
            'form':'indx', 'seld':1 },      # at index 1
        'form':'indx', 'seld':1 },    # and the library playlist is at
    index 1 in the source
        # In other words "library playlist 1 in source 1"
    'pTrm':'utxt'("Beck"),  # Parameter 2: Search term "Beck"
    'pAre':'kSrR'            # Parameter 3: artists, you say?

    Indices in Apple Events and AppleScript are 1-based.

    The only question that is obvious is whether there is at least one
    source, and whether that first source has at least one library playlist.

    > The code that throws this exception is:
    >
    > track_array = (SBElementArray *)[libraryPlaylist searchFor:theArtist
    > only :
    > 'kSrR']; //only artists
    >
    > (...where  libraryPlaylist = [[[[[iTunes sources ] objectAtIndex:0]
    > libraryPlaylists] objectAtIndex:0] retain]  )
    >
    > Similar exceptions are thrown for other operations as well, for
    > example when
    > retrieving user playlists, so it's not just the search part causing
    > problems.
    >
    > Any ideas? Could the problem be these users have multiple sources/
    > library
    > playlists in iTunes? If so, how do I find the main source/library
    > playlist
    > without explicitly asking the user for it?

    That's a question of how, specifically, to script iTunes. I can't help
    you with that. You might experiment with iTunes and AppleScript
    yourself, to see if you can get them to violate your assumption that
    there is a "library playlist 1 in source 1." You might then acquire a
    definition of what a "main" playlist is, and what it might look like.
    You might then be in a position to intelligently ask users
    experiencing this problem what their source/playlist structure is.

    Or I may be wrong that the object specifier is the problem. It's what
    I'd investigate, though.

    The applescript-users list might be able to offer strategies for
    scripting iTunes.

    — F
  • Thank you very much. That is just the information I was looking for.
    You are probably right about the object specifier being the problem. I
    was informed by one user he only had one source and one library
    playlist, but I think he might have been wrong.

    Happy holidays.

    On Dec 23, 2007 2:12 AM, Fritz Anderson <fritza...> wrote:
    > On 22 Dec 2007, at 8:41 AM, <slasktrattenator...> wrote:
    >
    >> A typical exception looks like this: Apple event returned an error.
    >> Event =
    >> 'hook'\'Srch'{ '----':'obj '{ 'want':'cLiP', 'from':'obj
    >> '{ 'want':'cSrc',
    >> 'from':'null'(), 'form':'indx', 'seld':1 }, 'form':'indx', 'seld':1 },
    >> 'pTrm':'utxt'("Beck"), 'pAre':'kSrR' }
    >>
    >> (That 'from':'null'() thing looks a little suspicious...)
    >
    > The null container in the Apple Event object model is the application
    > itself.
    >
    > '----':'obj '  # Direct object is an object(1) such that...
    > { 'want':'cLiP', 'from':'obj ' # (1)'s a library playlist from an
    > object(2) such that
    > { 'want':'cSrc', 'from':'null'(), # (2) is a source from the
    > application
    > 'form':'indx', 'seld':1 },      # at index 1
    > 'form':'indx', 'seld':1 },    # and the library playlist is at
    > index 1 in the source
    > # In other words "library playlist 1 in source 1"
    > 'pTrm':'utxt'("Beck"),  # Parameter 2: Search term "Beck"
    > 'pAre':'kSrR'            # Parameter 3: artists, you say?
    >
    > Indices in Apple Events and AppleScript are 1-based.
    >
    > The only question that is obvious is whether there is at least one
    > source, and whether that first source has at least one library playlist.
    >
    >> The code that throws this exception is:
    >>
    >> track_array = (SBElementArray *)[libraryPlaylist searchFor:theArtist
    >> only :
    >> 'kSrR']; //only artists
    >>
    >> (...where  libraryPlaylist = [[[[[iTunes sources ] objectAtIndex:0]
    >> libraryPlaylists] objectAtIndex:0] retain]  )
    >>
    >> Similar exceptions are thrown for other operations as well, for
    >> example when
    >> retrieving user playlists, so it's not just the search part causing
    >> problems.
    >>
    >> Any ideas? Could the problem be these users have multiple sources/
    >> library
    >> playlists in iTunes? If so, how do I find the main source/library
    >> playlist
    >> without explicitly asking the user for it?
    >
    > That's a question of how, specifically, to script iTunes. I can't help
    > you with that. You might experiment with iTunes and AppleScript
    > yourself, to see if you can get them to violate your assumption that
    > there is a "library playlist 1 in source 1." You might then acquire a
    > definition of what a "main" playlist is, and what it might look like.
    > You might then be in a position to intelligently ask users
    > experiencing this problem what their source/playlist structure is.
    >
    > Or I may be wrong that the object specifier is the problem. It's what
    > I'd investigate, though.
    >
    > The applescript-users list might be able to offer strategies for
    > scripting iTunes.
    >
    > — F
    >
    >
previous month december 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
31            
Go to today