Help with Notification Center Delegate

I can’t seem to get my delegate handler called, userNotificationCenter_shouldPresentNotification_ never gets called. I wanted to return “no” but the notification still appeared. Oddly the code below works fine if I just put the code in the script editor but fails when its placed within applicationWillFinishLaunching of a Applescript-Cocoa app.

Any ideas?

Thanks in advance, Scott


    on applicationWillFinishLaunching:(aNotification)
        set theNotif to current application's NSUserNotification's alloc()'s init()
        
        tell theNotif
            setTitle_("A title")
            setInformativeText_("This is some information")
            setHasActionButton_(true)
            setActionButtonTitle_("Ok")
            setOtherButtonTitle_("Cancel")
        end tell
        
        tell current application's NSUserNotificationCenter's defaultUserNotificationCenter()
            setDelegate_(me)
            deliverNotification_(theNotif)
        end tell
        
    end applicationWillFinishLaunching:

    on userNotificationCenter_shouldPresentNotification_(center, notification)
        display dialog "userNotificationCenter_shouldPresentNotification_"
        
        return no
    end userNotificationCenter_shouldPresentNotification_
    
    on userNotificationCenter_didActivateNotification_(center, notification)
        display dialog "userNotificationCenter_didActivateNotification_"
    end userNotificationCenter_didActivateNotification_

Ahh must be something in using a notification in applicationWillFinishLaunching. If I put the same code behind a button it works fine. Somehow the delegate isn’t getting called when the notification is triggered from applicationWillFinishLaunching.

Just a guess but maybe it has to do with the colons used in applicationWillFinishLaunching: ? Shouldn’t it be _ ?

I’ve never had trouble calling a notification or setting one up from that handler before. Shouldn’t be a problem.

Browser: Safari 9537.53
Operating System: Mac OS X (10.8)

Try applicationDidFinishLaunching instead.

No – that’s the new syntax in 10.9. The fact that the script uses both forms suggests it’s been edited directly in Xcode, rather than an external editor. Underscores are also still used in some circumstances, such as a method call in a statement of its own within a tell block.

I see. something new :slight_smile:

There was quite a big change in 10.9, especially in terms of ASObjC.