AppleScriptObjC based Service

First of all I know very little about AppleScriptObjC so pardon me if I am doing something very stupid. I am trying to add a service provider to my application and am having some problems. Based upon the ObjC example I need to do something like: [NSApp setServicesProvider:MyServiceClass];
Based on my reading NSApp = class “NSApplication” of current application
So in my AppDelegate I have the following:


script fooAppDelegate
	property parent : class "NSObject"
	property MyService : missing value
	
	on applicationWillFinishLaunching_(aNotification)
		(class "NSApplication" of current application)'s setServicesProvider_(MyService)
		MyService's test_("fire")
	end applicationWillFinishLaunching_
	
end script

With a corresponding class for MyService that looks like:


script MyService
	property parent : class "NSObject"
    
	property pboard : class "NSPasteboard"
	property userData : ""
	property theError : ""
	
	on getRevisions___(pboard, userData, theError)
		log "I am a service"
	end getRevisions___
	
	on test_(testedBy)
		log "I have been tested by " & testedBy
	end test_
end script

This is what I get in the console:
1/4/10 1:26:22 PM foo[88608] +[NSApplication setServicesProvider:]: unrecognized selector sent to class 0x7fff70318bb0
1/4/10 1:26:22 PM foo[88608] *** -[fooAppDelegate applicationWillFinishLaunching:]: +[NSApplication setServicesProvider:]: unrecognized selector sent to class 0x7fff70318bb0 (error -10000)

if I comment out the setServicesProvider_ line I can verify that the MyService class seems to work well enough to allow me to call the test method:
1/4/10 1:26:56 PM foo[88636] I have been tested by fire

So what am I doing wrong? I mean besides probably everything.

I wonder if you need to use applicationDidFinishLaunching instead of applicationWillFinishLaunching…

Hang on – the problem is that setServicesProvider: is an instance method – you need an instance of NSApplication. Something like:

set theApp to current application's class "NSApplication"'s sharedApplication()
theApp's setServicesProvider_(MyService)

Yep that was it. I still need to make the service actually do something but at least my handler is being called or it was after I removed the error parameter and one underscore
So my revised hander is:


on getRevisions__(pboard, userData)
	log "I am a service"
end getRevisions__

Once I get this all working I’ll write it up for posterity.