OSX Notifications - Starting Point

Haiku style :

dim s as new shell s.execute("osascript -e 'display notification ""Hello, World"" with title ""Message""'")

Lots of additional options at https://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html

Method style

  • Create this in AppleScript Editor utility :

on run {notif, titler} display notification notif with title titler end run

  • Save as “notification.scpt”
  • Drag notification.scpt in the project

Call from Xojo using :

notification("world","hello")

This solution is better than the osascript one since the notification will have the app icon and will be listed under the app name in the notification center.
With osascript the sender application will be Applescript (so will have AppleScript Icon and will be listed under AppleScript)

[quote=127390:@Antonio Rinaldi]This solution is better than the osascript one since the notification will have the app icon and will be listed under the app name in the notification center.
With osascript the sender application will be Applescript (so will have AppleScript Icon and will be listed under AppleScript)[/quote]

I mentioned the osascript one liner as sort of a reference to the caterpillar machine of my previous post.

You are right, the method way is better. And it can be enriched the same way with the Apple reference.

I’m testing usernotification. I’m on MacOsx 10.9.5 and Xojo 2015R2. Both shao sean cocoa declares and MBS plugin
doesn’t work. I Have no errors but no notification pops up.
Any idea ?
Thanks

well, your app has an application identifier?
And in prefs is allowed to show notifications?

I can run my example project, click button “show now” and notification shows.

I am using the MBS solution often and have no issues so far. So, i can highly recommend it.

My declares are probably a result of hacking other people’s declares, so best to work with MBS plugins or macoslib… If neither of those projects are working for you, then I would suspect there is something with your system (do you allow your app to show notifications? are you “do not disturb” mode?)

Stupid question: Have you checked the notifications setting for your app in system preferences? Could be it is set to “none”.
And is your app in foreground? If so, you have to return “true” on the shouldPresentNotification Event of the UserNotificationCenterDelegate. If you don’t, notifications do only show up when the app is in background.

Using the apple script call by shell I have no issues.
Other application are show regularly notification.
Asking to what Christian pointing, where do I have to check ‘prefs’ ?
Maybe shao sean could you post a complete sample on how to use your module for OS notification ?
Do I have necessarily use the event delegate ?
Thanks in advance.
C

I have checked in mac OSX system preferences and the app is in the list of notification’s application and is active.

Makte sure the notification settings are set to banner and then program a delayed notification, in case your implementation doesn’t allow you to via a timer. Then send the app to the background and wait for the timer to trigger. I guess the notification will show up now. Like said, without using the delegate notifications only work for background apps. If it’s in the foreground, Apple thinks you have better means to signalize the situation.
Maybe this old project helps you to – I haven’t checked if it still runs and I will not continue the single module OS X additions; after all, many classes need a lot of other OS X classes so I think a full library is a better way:
https://dl.dropboxusercontent.com/u/21200221/Xojo/MacOSUserNotification%20Demo.xojo_xml_project.zip

Look for the “present always” button at the bottom. When it’s set, the delegate returns true.

Carlo, have you checked if the notification is in the notification list? If your app is front most without a delegate the notification will be delivered (and you can see in the notification list) but you will not see the notification.

Thanks to all for suggestion. I have found where I was wrong. To test I used only local variables, instanciated into a button action event. I see that I have to use global properties like:
m = new NSUserNotificationCenterMBS
d = new MyNSUserNotificationCenterDelegateMBS
This appens for MBS implementation
Instead, about shao sean cocoa module, I have not working code:
// don’t work
DIM notification As NEW Dictionary
notification.Value(“title”) = “Hello”
notification.Value(“subtile”) = “World”
notification.Value(“informativeText”) = “mmm… notifications”
//notification.Value(“icon”) = aXojoPicture // don’t use this in apps for MAS though

Cocoa.DeliverNotification notification

I just had the idea for a ‘FakeNotification’
should also work in Windows

[quote=191518:@Axel Schneider]I just had the idea for a ‘FakeNotification’
should also work in Windows[/quote]

I use a similar technique in my latest Windows app. Nice job.

Windows notifications appear at the bottom of the screen, right along the top of the taskbar, so notif.top should be Screen(0).availableHeight-notif.Height. The size of Notif is just fine. The text label should be multiline and left justified. Also, Timer should be faster. The animation for notification show is too slow. I guess a period of 3-5 should be fine.

The only drawback of using fake notifications under Windows is that in Windows 10, there is now a bar (think slide in pane) which can be displayed where the Charm bar was, where all notifications are logged. Of course the Xojo made notifications will not appear there. But it is probably not big deal.

The Windows 10 Notification Center :

  me.left = Screen(0).AvailableWidth
  #if TargetCocoa then
    me.top = Screen(0).availableTop
  #elseif TargetWin32 then
    me.top = Screen(0).availableHeight-notif.Height
  #endif

With a period < 10, it is not faster (OSX)
Why?

Period 10 - 76 Ticks
Period 2 - 76 Ticks

[quote=191704:@Axel Schneider] me.left = Screen(0).AvailableWidth #if TargetCocoa then me.top = Screen(0).availableTop #elseif TargetWin32 then me.top = Screen(0).availableHeight-notif.Height #endif

With a period < 10, it is not faster (OSX)
Why?

Period 10 - 76 Ticks
Period 2 - 76 Ticks[/quote]

As Christian Schmitz mentions in another thread, Windows timers cannot go below 60ms or so.

The solution is to accelerate the step. This provides a speed roughly equivalent to native Windows notifications :

Sub Action() #If TargetWin32 then notif.left = max(notif.left -10,screen(0).AvailableWidth - notif.Width) #else notif.left = max(notif.left -4,screen(0).AvailableWidth - notif.Width) #endif mycount = mycount + 1 if mycount = 75 then me.mode = 0 notif.left = Screen(0).AvailableWidth - notif.Width main.show end if End Sub

Now this is really nice.

Make sure to set the message label to Multiline. Otherwise all lines are stuck on top of each other under Windows.

From that screenshot - I presume that Windows 10 has a black UI and and a notifications slide in sidebar - just like OS X.
That looks interesting :slight_smile: