MenuApp Errors

I’m try to adapt Jonn8’s MenuApp to work with my app (http://www.jonn8.com/html/MenuApp_ASOC.html).

I’m getting this error whenever I run the program:

2010-04-24 14:33:57.333 MenuWeather[52005:a0f] *** -[MenuWeatherAppDelegate applicationWillFinishLaunching:]: NSConcreteAttributedString initWithString:: nil value (error -10000)

here’s the code:

[code]script MenuWeatherAppDelegate
property parent : class “Enhancer” of current application
property NSMenu : class “NSMenu”
property NSMenuItem : class “NSMenuItem”
property statusMenu : missing value
property dynamicMenu : missing value
property statusItemController : missing value

on |idle|()
	return 1.0
end |idle|

on about_(sender)
	activate
	current application's NSApp's orderFrontStandardAboutPanel_(null)
end about_

on quit_(sender)
	quit
end quit_

on applicationWillFinishLaunching_(notification)
	set statusMenu to (my NSMenu's alloc)'s initWithTitle_("statusMenu")
	set menuItem to (my NSMenuItem's alloc)'s init
	menuItem's setTitle_("About MenuApp")
	menuItem's setTarget_(me)
	menuItem's setAction_("about:")
	menuItem's setEnabled_(true)
	statusMenu's addItem_(menuItem)
	menuItem's release()
	statusMenu's addItem_(my NSMenuItem's separatorItem)
	
	set menuItem to (my NSMenuItem's alloc)'s init
	menuItem's setTitle_("Quit MenuApp")
	menuItem's setTarget_(me)
	menuItem's setAction_("quit:")
	menuItem's setKeyEquivalent_("q")
	menuItem's setEnabled_(true)
	statusMenu's addItem_(menuItem)
	menuItem's release()
	
	set statusItemController to (current application's class "JEN_StatusItemController"'s alloc)'s init
	statusItemController's createStatusItemWithMenu_(statusMenu)
	statusMenu's release()
	my enableIdle()
end applicationWillFinishLaunching_

on applicationShouldTerminate_(sender)
	-- Insert code here to do any housekeeping before your application quits 
	return my NSTerminateNow
end applicationShouldTerminate_

on applicationWillTerminate_(notification)
	statusItemController's releaseStatusItem()
	statusItemController's release()
end applicationWillTerminate_

end script[/code]
That Enhancer thing at the top is so i can get the idle handler.

Add some log commands to narrow down where the error is.

This line seems to be the problem:

statusItemController's createStatusItemWithMenu_(statusMenu)

The createStatusItemWithMenu: method calls upDateDisplay, which includes an initWithString: call, so that might give you some clue. It might suggest the title is the problem; try throwing away the app’s preferences and try again.

The app has no preferences. the code i posted is all there is so far.

The Objective-C class is trying to read preferences. The line:

	NSString *title = [standardUserDefaults stringForKey:@"menu_title"];

is trying to read from user defaults, and the line:

	NSAttributedString *titleAttributedString = [[[NSAttributedString alloc] initWithString:title attributes:attributes] autorelease];

is trying to use the result, and probably erroring.

The sample script in MenuApp.app registers defaults at startup, and I suspect you need to do the same.

thanks, it’s working now. I still have one problem that doesn’t seem to be related though.

When I try to quit, I get this error:

[<Enhancer 0x1000031c0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key NSTerminateNow.

here’s the thread I got the enhancer script from: http://macscripter.net/viewtopic.php?id=30539

Change:

return my NSTerminateNow

to

return current application's NSTerminateNow

It was a mistake in the project template fixed in 10.6.3.

thanks, worked perfectly