2005-05-07

Running the Weather widget outside dashboard

Create a new Cocoa application in Xcode, drag a WebView into your window, fight Interface Builder to create a new subclass of NSObject with an outlet "webView" connected to the WebView, and put this method in the generated .m file:

#import "WeatherController.h"

@implementation WeatherController

- (void) awakeFromNib {
[NSApp setApplicationIconImage:
[[NSImage alloc] initWithContentsOfURL:
[NSURL URLWithString:@"file:///Library/Widgets/Weather.wdgt/Icon.png"]]];
[[webView mainFrame] loadRequest:
[NSURLRequest requestWithURL:
[NSURL URLWithString:@"file:///Library/Widgets/Weather.wdgt/Weather.html"]]];
}

@end

The loadRequest: line I copied from the WebKit documentation; the other line I guessed. All use of Apple's widget (and its icon) is done by reference rather than by copy, so there's no way for Apple or AccuWeather to get upset.

To be able to run outside Xcode, you have to rebuild your project for "Deployment" rather than "Development". Weird.