Question

I'm trying to override the +initialize method of a class using ASOC, but I cannot find a way to override a class method. Is it even possible?

Not to let any confusion possible about the language I'm talking about, here's some code:

script FLAppDelegate
    property parent: class "NSObject"

    -- -- Class Methods -- --
    -- Insert code here

end script
Was it helpful?

Solution

I've done some tests, and as far as I can tell, weird as it is, methods defined using AppleScriptObjC are both class and instance methods.

Let's say I have an AppleScriptObjC file:

script iTunesController
   property parent: class "NSObject"

   on playpause()
      tell application id "com.apple.iTunes" to playpause
   end playpause
end script

In an Objective-C method, both:

- (void)callASOC
{
   iTunesControllerInstance = [NSClassFromString(@"iTunesController") new];
   [iTunesControllerInstance playpause];
   [iTunesControllerInstance release];
}

and

- (void)callASOC
{
   [NSClassFromString(@"iTunesController") playpause];
}

will call the playpause handler in the AppleScriptObjC file. The latter formulation will generate a warning a compile time, but works.

I was not able to find any documentation confirming or refuting this.

OTHER TIPS

Thanks to @Friziab who reminded me of the NSClassFromString

So I could call a AppleScriptObjC method in my AppDelegate.applescript from another class (script) (NSView subclass)

I don't use AppleScriptObjC so there may be a proper way of doing it but this worked

 current application's  NSClassFromString("AppDelegate")'s popWindow()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top