If you won’t use a helper app, you will have to use AppleScriptObjC:
set theNotif to current application's NSUserNotification's alloc()'s init()
tell theNotif
setTitle_("A title")
setInformativeText_("This is some information")
end tell
tell current application's NSUserNotificationCenter's defaultUserNotificationCenter() to deliverNotification_(theNotif)
Could you go int more details on how to use the script you posted? If I run it as a normal script I get error "žNSUserNotification" versteht die Nachricht žalloc" nicht." number -1708 from NSUserNotification.
When I create a new script with the “Cocoa-Apple Script-Applet” template, paste the code and execute it, a message is displayed once (multiple executions don’t create multiple messages) but its only created in the background in the notification center without a notification window.
Is there a way to display a notification window?
AppleScript: 2.2.2
Browser: Safari 537.4
Operating System: Mac OS X (10.8)
The user controls that via the Notifications panel of System Preferences. Even then, I think the dialogs don’t appear if the application sending the notification is front-most. And you can add an entry to the app’s Info.plist file for NSUserNotificationAlertStyle to set the default style (although the user always has last say).
file > new from template > Cocoa-AppleScript Applet
paste
set theNotif to current application's NSUserNotification's alloc()'s init()
tell theNotif
setTitle_("A title")
setInformativeText_("This is some information")
end tell
tell current application's NSUserNotificationCenter's defaultUserNotificationCenter() to deliverNotification_(theNotif)
4.Script > Run Application or file > save > fileformat application
both result in the same thing no notification in the notification center and the app just doesn’t execute in 10.8
Your app is frontmost when you run it. You can make your script the user notification centre’s delegate and override this action like this:
set theNotif to current application's NSUserNotification's alloc()'s init()
tell theNotif
setTitle_("A title")
setInformativeText_("This is some information")
end tell
tell current application's NSUserNotificationCenter's defaultUserNotificationCenter()
setDelegate_(me)
deliverNotification_(theNotif)
end tell
on userNotificationCenter_shouldPresentNotification_(cen, notif) -- delegate method
return yes
end userNotificationCenter_shouldPresentNotification_
This works fine, when I create new ASObjC script and simply paste, but when I have something like:
on initObject()
script theObject
on notify()
set theNotif to current application's NSUserNotification's alloc()'s init()
tell theNotif
setTitle_("A title")
setInformativeText_("This is some information")
end tell
tell current application's NSUserNotificationCenter's defaultUserNotificationCenter()
setDelegate_(me)
deliverNotification_(theNotif)
end tell
end notify
on userNotificationCenter_shouldPresentNotification_(cen, notif) -- delegate method
return yes
end userNotificationCenter_shouldPresentNotification_
end script
return theObject
end initObject
When I init the object like:
use theObject : script "theObjectScript"
set instanceOfObject to theObject's initObject()
instanceOfObject's notify()
The OSX Mavericks’s AppleScript editor throws system exception on the problem with delegate method, am I doing something wrong???