Scripting Bridge woes

40 views
Skip to first unread message

Duncan Campbell

unread,
Oct 13, 2010, 6:04:16 PM10/13/10
to cocoa-...@googlegroups.com
Hey folks,

I'm hoping someone with some Scripting Bridge exp. can help out with a problem I'm having:

I'm trying to add an MP3 to iTunes, and then update its meta info - all via Scripting Bridge (actually I want to add a lot of MP3's - this example is just to show the issue I'm having).

My code is something similar to:

iTunesApplication *iTunesApp = [[SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"] retain];
[iTunesApp setDelegate:self];

NSURL *mp3Url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp3"]];
iTunesTrack *t = [iTunesApp add:[NSArray arrayWithObject:aUrl] to:nil];

[t setName:@"some name"];
[t setArtist:@"some artist"];
[t setAlbum:@"some album name"];

This works fine for iTunes 9, but in iTunes 10 not so. I can only set a single property after adding the track (so any of the 3 set's will work if the other 2 are commented-out) - the second time I set a property I get errors ("OSStatus error -50 - error in user parameter list" and "OSStatus error -54 permissions error on file open").

Looking through the SB documentation I see that SBObjects are lazily evaluated, and will only be returned when you request some concrete data - and this does indeed seem to be connected to the problem as if I NSLog() my track before attempting to set any properties then it fails right after and I can't set anything.

Here's the weird thing though: if I sleep() (for around 3 seconds on my test machine) right after adding the track then everything then works correctly. Everything also works correctly if the track already exists in iTunes (so isn't actually added) - so there seems to be some task that iTunes (or SB) is doing when a track is added that causes things to fail.

Oh, and I've also tried re-quering the iTunes Library playlist for the newly added track and then setting properties on it instead, but I get the same issues.

Can anyone shed any light on what might be going on and a possible solution?

---------------------------------------------------------------
Duncan Campbell
http://objective-d.com
Twitter: dunk
---------------------------------------------------------------

Raf Fiol

unread,
Jul 10, 2012, 3:33:48 PM7/10/12
to cocoa-...@googlegroups.com
I experienced the exact same thing.  Only one "set" would work.  I tried adding the sleep(3) after the add (as suggested above) and that seems to work.  But it's not a great solution.
Reply all
Reply to author
Forward
0 new messages