Sign in Join
Wiki copytemporary

Show Badge on Application Icon in Dock: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Show Badge on Application Icon in Dock

OldNewLine
1+*(macOS only)*
2+
3+## Overview
4+
5+Badges are used to notify a user of something new in an application. The badge is a counter that appears on the application's dock tile (icon) as a white number on a red circular or oval, depending on the number of digits, background. What the number represents depends on the application - it might be the number of new emails in an email application, new iMessages, unfinished Reminders, missed FaceTime calls, the number of outstanding application updates, etc.
6+
7+## Example code
8+
9+This example shows you how to implement notification badges in an application.
10+
11+``` pascal
12+unit Unit1;
13+
14+{$mode objfpc}{$H+}
15+{$modeswitch objectivec2}
16+
17+interface
18+
19+uses
20+ Classes, SysUtils, Forms, Dialogs, StdCtrls,
21+ CocoaAll;
22+
23+type
24+
25+ { TForm1 }
26+
27+ TForm1 = Class(TForm)
28+ Button1: TButton;
29+ Button2: TButton;
30+ procedure Button1Click(Sender: TObject);
31+ procedure Button2Click(Sender: TObject);
32+ private
33+
34+ public
35+
36+ end;
37+
38+var
39+ Form1: TForm1;
40+
41+implementation
42+
43+{$R *.lfm}
44+
45+{ TForm1 }
46+
47+procedure TForm1.Button1Click(Sender: TObject);
48+begin
49+ // Display badge text on the dock tile (icon)
50+ NSApp.dockTile.setBadgeLabel(NSStr('1'));
51+end;
52+
53+procedure TForm1.Button2Click(Sender: TObject);
54+begin
55+ // Remove badge text from the dock tile (icon)
56+ NSApp.dockTile.setBadgeLabel(Nil);
57+end;
58+
59+end.
60+```
61+
62+## See also
63+
64+- [[Application disable resize over Dock]]
65+- [[Bounce Application Icon in Dock]]
66+- [[Hiding a macOS app from the Dock]]
67+- [[macOS Application Dock Menu]]
68+
69+## External links
70+
71+- [Apple: NSApplication](https://developer.apple.com/documentation/appkit/nsapplication).
72+- [Apple: NSDockTile](https://developer.apple.com/documentation/appkit/nsdocktile).
73+
74+---
75+*From the Free Pascal wiki, page "Show Badge on Application Icon in Dock", as it stood on 2022-05-15 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
76+Category: Code Snippets
77+Category: Lazarus
78+Category: Platform-sensitive development
79+Category: macOS

Back to history