1import Cocoa
2
3// Compilation: swiftc badge.swift -o badge
4// Usage: ./badge <count>
5
6let args = ProcessInfo.processInfo.arguments
7guard args.count > 1 else {
8 print("Usage: \(args[0]) <count>")
9 exit(1)
10}
11
12let countString = args[1]
13let label = countString == "0" ? "" : countString
14
15// Note: This only works if the process has a Dock icon (is a bundled app or has activation policy set)
16// For a CLI tool, this would set the badge of the Terminal app if run directly,
17// which might not be what's intended.
18// However, if we run this from our 'MatchaMail.app' shim, it will work for that app.
19
20NSApp.dockTile.badgeLabel = label
21NSApp.dockTile.display()
22
23// Give it a tiny bit of time to propagate
24RunLoop.main.run(until: Date(timeIntervalSinceNow: 0.1))