sorry, i have another question about "WebScriptObject callWebScriptMethod" :
i used **[webScriptObject callWebScriptMethod:@"_updateInfo" withArguments:args];** to call javascript _updateInfo function. it can be called with correct parameters. however, it complains document.getElementById("f_name") is null. i don't know how to access the html element after called from widget plugin. following is in javascript : function _updateInfo(currentTrack) { if (currentTrack != "NOT RUNNING" && currentTrack != "NOT PLAYING") { var info = currentTrack.split("|"); song = info[0]; album = info[1]; artist = info[2]; //document.getElementById("f_name").innerHTML = song; //document.getElementById("f_album_artist").innerHTML = album + " - " + artist; } else { // idle(); } } following is part of codes in xcode : - (void) windowScriptObjectAvailable:(WebScriptObject *) scriptObj { [scriptObj setValue:self forKey:@"pTunes"]; webScriptObject = scriptObj; [webScriptObject retain]; } (omit) NSArray* args = [NSArray arrayWithObjects: trackInfo, nil]; [webScriptObject callWebScriptMethod:@"_updateInfo" withArguments:args]; i've read ADC documentation, but i still can't figure it out. please teach me. thank you in advance. best, sam On Tue, Jan 12, 2010 at 9:51 PM, Sam Tseng <samtz1...@gmail.com> wrote: > hi, > > i would like to implement a widget plugin to detect iTunes current > artist and current album call back to widget. i ran my widget plugin > in dashcode without crashing. however, i deployed the widget into > dashboard, it crashed all the time. following is part of my codes, > could any one give me hints to tell me which part may cause this > problem. thank you for your help. :) > > - (id) initWithWebView:(WebView*)webView > { > self = [super init]; > iTunes = [SBApplication > applicationWithBundleIdentifier:@"com.apple.iTunes"]; > pTunesRun = TRUE; > previousdatabaseID = @""; > [NSThread detachNewThreadSelector:@selector(checkiTunesStatus) > toTarget:self withObject:nil]; > return self; > } > > - (void) checkiTunesStatus > { > NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; > while (pTunesRun) { > if ([iTunes isRunning]) { > if ([iTunes playerState] == iTunesEPlSPaused || [iTunes > playerState] == iTunesEPlSStopped) { > trackInfo = [NSString stringWithFormat: @"%s", > "NOT PLAYING"]; > } else { > if (!iTunes.currentTrack.artist || > !iTunes.currentTrack.album) > trackInfo = [NSString > stringWithFormat: @"%@|NULL|NULL", > iTunes.currentTrack.name]; > else if (!iTunes.currentTrack.artist) > trackInfo = [NSString > stringWithFormat: @"%@|%@|NULL", > iTunes.currentTrack.name, iTunes.currentTrack.album]; > else if (!iTunes.currentTrack.album) > trackInfo = [NSString > stringWithFormat: @"%@|NULL|%@", > iTunes.currentTrack.name, iTunes.currentTrack.artist]; > else > trackInfo = [NSString > stringWithFormat: @"%@|%@|%@", > iTunes.currentTrack.name, iTunes.currentTrack.album, > iTunes.currentTrack.artist]; > } > currentdatabaseID = [NSString stringWithFormat: @"%d", > iTunes.currentTrack.databaseID]; > } else { > trackInfo = [NSString stringWithFormat: @"%s", "NOT > RUNNING"]; > } > if (autoRefresh) { > if (![previousdatabaseID isEqualToString: > currentdatabaseID]) { > NSArray* args = [NSArray arrayWithObjects: > trackInfo, > nil]; > [webScriptObject > callWebScriptMethod:@"_updateInfo" withArguments:args]; > previousdatabaseID = [NSString > stringWithFormat: @"%@", currentdatabaseID]; > } > } > [NSThread sleepForTimeInterval:1.0]; > } > [pool release]; > [NSThread release]; > } > > best, sam > -- Sam Tseng Academia Sinica Institute of Astronomy and Astrophysics Tel: +886-2-2366-5392 Fax: +886-2-2367-7849
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com