{"id":13479483,"url":"https://github.com/maximbilan/Mac-OS-X-App-Menu-Bar-Popup","last_synced_at":"2025-03-27T09:32:41.098Z","repository":{"id":76126094,"uuid":"44683421","full_name":"maximbilan/Mac-OS-X-App-Menu-Bar-Popup","owner":"maximbilan","description":"Mac OS X Application like a menu bar popup message","archived":false,"fork":false,"pushed_at":"2018-09-21T14:51:01.000Z","size":906,"stargazers_count":191,"open_issues_count":1,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-11T05:02:18.943Z","etag":null,"topics":["macosx","menubar","popup","popup-message","tutorial"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maximbilan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-10-21T14:51:09.000Z","updated_at":"2024-11-28T09:02:58.000Z","dependencies_parsed_at":"2023-02-25T05:30:43.010Z","dependency_job_id":null,"html_url":"https://github.com/maximbilan/Mac-OS-X-App-Menu-Bar-Popup","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximbilan%2FMac-OS-X-App-Menu-Bar-Popup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximbilan%2FMac-OS-X-App-Menu-Bar-Popup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximbilan%2FMac-OS-X-App-Menu-Bar-Popup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximbilan%2FMac-OS-X-App-Menu-Bar-Popup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maximbilan","download_url":"https://codeload.github.com/maximbilan/Mac-OS-X-App-Menu-Bar-Popup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245817633,"owners_count":20677324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["macosx","menubar","popup","popup-message","tutorial"],"created_at":"2024-07-31T16:02:17.301Z","updated_at":"2025-03-27T09:32:40.773Z","avatar_url":"https://github.com/maximbilan.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# Mac OS X Application like a menu bar popup message\n\nA simple tutorial which explains how to create Mac OS X application as a menu bar popup message.\u003cbr\u003e\nLike that:\n\n![alt tag](https://raw.github.com/maximbilan/Mac-OS-X-App-Menu-Bar-Popup/master/screenshots/1.png)\n\nFor that, we need to create \u003ci\u003eEventMonitor\u003c/i\u003e class for handling monitor events.\n\n\u003cpre\u003e\nimport Cocoa\n\nopen class EventMonitor {\n\t\n\tfileprivate var monitor: AnyObject?\n\tfileprivate let mask: NSEventMask\n\tfileprivate let handler: (NSEvent?) -\u003e ()\n\t\n\tpublic init(mask: NSEventMask, handler: @escaping (NSEvent?) -\u003e ()) {\n\t\tself.mask = mask\n\t\tself.handler = handler\n\t}\n\t\n\tdeinit {\n\t\tstop()\n\t}\n\t\n\topen func start() {\n\t\tmonitor = NSEvent.addGlobalMonitorForEvents(matching: mask, handler: handler) as AnyObject?\n\t}\n\t\n\topen func stop() {\n\t\tif monitor != nil {\n\t\t\tNSEvent.removeMonitor(monitor!)\n\t\t\tmonitor = nil\n\t\t}\n\t}\n}\n\u003c/pre\u003e\n\nAnd the example of \u003ci\u003eAppDelegate\u003c/i\u003e:\n\n\u003cpre\u003e\nimport Cocoa\n\n@NSApplicationMain\nclass AppDelegate: NSObject, NSApplicationDelegate {\n\n\tlet statusItem = NSStatusBar.system().statusItem(withLength: -2)\n\tlet popover = NSPopover()\n\tvar eventMonitor: EventMonitor?\n\n\tfunc applicationDidFinishLaunching(_ aNotification: Notification) {\n\t\t\n\t\tif let button = statusItem.button {\n\t\t\tbutton.image = NSImage(named: \"StatusBarButtonImage\")\n\t\t\tbutton.action = #selector(AppDelegate.togglePopover(_:))\n\t\t}\n\t\t\n\t\tlet mainViewController = NSStoryboard(name: \"Main\", bundle: nil).instantiateController(withIdentifier: \"ViewControllerId\") as! ViewController\n\t\t\n\t\tpopover.contentViewController = mainViewController\n\t\t\n\t\teventMonitor = EventMonitor(mask: [.leftMouseDown, .rightMouseDown]) { [unowned self] event in\n\t\t\tif self.popover.isShown {\n\t\t\t\tself.closePopover(event)\n\t\t\t}\n\t\t}\n\t\teventMonitor?.start()\n\t}\n\n\tfunc applicationWillTerminate(_ aNotification: Notification) {\n\t}\n\n\tfunc togglePopover(_ sender: AnyObject?) {\n\t\tif popover.isShown {\n\t\t\tclosePopover(sender)\n\t\t} else {\n\t\t\tshowPopover(sender)\n\t\t}\n\t}\n\t\n\tfunc showPopover(_ sender: AnyObject?) {\n\t\tif let button = statusItem.button {\n\t\t\tpopover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)\n\t\t}\n\t\teventMonitor?.start()\n\t}\n\t\n\tfunc closePopover(_ sender: AnyObject?) {\n\t\tpopover.performClose(sender)\n\t\teventMonitor?.stop()\n\t}\n\n}\n\u003c/pre\u003e\n\nIt’s really simple and I think no sense to describe details, just see the code.\n\nFull code of this example you can find in this repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximbilan%2FMac-OS-X-App-Menu-Bar-Popup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximbilan%2FMac-OS-X-App-Menu-Bar-Popup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximbilan%2FMac-OS-X-App-Menu-Bar-Popup/lists"}