Unable to set a dock tile badge?

I know I did this in the past, and the code is not much so there wouldn’t be a lot to miss. But apparently I am unable to set the badge string for a macOS docktile in Monterey 12.2.1.
What am I missing?

Both are not working – the declares copied from the forum:

Declare Function NSClassFromString Lib "Foundation" (ClassName As CFStringRef) As Integer
Declare Function sharedApplication Lib "AppKit" Selector "sharedApplication" (classRef As Integer) As Integer
Declare Function getDockTile Lib "AppKit" Selector "dockTile" (NSApplicationInstance As Integer) As Integer
Declare Sub setBadgeLabel Lib "AppKit" Selector "setBadgeLabel:" (NSDockTileInstance As Integer, NSStringValue As CFStringRef)
Declare Sub setshowsApplicationBadge Lib "AppKit" Selector "setShowsApplicationBadge:" (id As Integer, value As Boolean)
setBadgeLabel(getDockTile(sharedApplication(NSClassFromString("NSApplication"))), "Hallo Welt")
setshowsApplicationBadge(getDockTile(sharedApplication(NSClassFromString("NSApplication"))), True)
//
Var a As NSApplicationMBS = NSApplicationMBS.sharedApplication
var tile As NSDockTileMBS = a.dockTile
Tile.badgeLabel = "Hallo Welt"
Tile.showsApplicationBadge = True

Works fine here (Monterey 12.3.1) :wink:

Declare Function NSClassFromString Lib "Foundation" (ClassName As CFStringRef) As Ptr
Declare Function sharedApplication Lib "AppKit" Selector "sharedApplication" (classRef As Ptr) As Ptr
Declare Function getDockTile Lib "AppKit" Selector "dockTile" (NSApplicationInstance As Ptr) As Ptr
Declare Sub setBadgeLabel Lib "AppKit" Selector "setBadgeLabel:" (NSDockTileInstance As Ptr, NSStringValue As CFStringRef)
Declare Sub setShowsApplicationBadge Lib "AppKit" Selector "setShowsApplicationBadge:" (id As Ptr, value As Boolean)

Var oSharedApplication As Ptr = sharedApplication(NSClassFromString("NSApplication"))
Var oDockTile As Ptr = getDockTile(oSharedApplication)

setBadgeLabel(oDockTile, "Hallo Welt")
setShowsApplicationBadge(oDockTile, True)

BadgeLabel

the quoted MBS code works fine here.

Make sure your app has an unique bundle identifier.

Thank you both!
Sadly, no change. Of course there’s a bundle ID, I checked that the badge set code is being run, but the app icon stays clean.
Sometimes I am puzzled, to say the least. Usually it’s a stupid mistake that creates such things, but I am currently out of ideas for own stupidity.

Addition:
Console examination showed this line. Could it be connected?
I am now running 12.3.1 too.

setShowsApplicationBadge: is not yet implemented for the NSApp dockTile

My guess would be that you may be calling it too early? In the app class, constructor or open event.

Thanks, but no.
But I finally, finally found it. When I noticed in Console that UNNotificationCenter’s permission request failed. For whatever unclear reason, notifications had been turned off for this app. I swear I cannot have done that intentionally. And apparently there is now even a checkbox for “App Symbol Notifications”. Possibly part of Apple’s focus idea.
Or did this linger here for longer and I never saw it?

1 Like