All Projects → maximbilan → Mac Os X App Menu Bar Popup

maximbilan / Mac Os X App Menu Bar Popup

Licence: mit
Mac OS X Application like a menu bar popup message

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Mac Os X App Menu Bar Popup

Spotify Now Playing
Spotify now playing information and control popup for macOS menu bar
Stars: ✭ 171 (+1.79%)
Mutual labels:  popup, menubar
rktmachine
Menu bar macOS app for running rkt in a macOS hypervisor CoreOS VM.
Stars: ✭ 31 (-81.55%)
Mutual labels:  menubar, macosx
Xbar
Put the output from any script or program into your macOS Menu Bar (the BitBar reboot)
Stars: ✭ 15,693 (+9241.07%)
Mutual labels:  macosx, menubar
Acelink
Play Ace Streams in VLC on macOS.
Stars: ✭ 411 (+144.64%)
Mutual labels:  macosx, menubar
Ambar-Xamarin
A macOS Menu Bar app built with Xamarin and C#
Stars: ✭ 63 (-62.5%)
Mutual labels:  popup, macosx
Electron
This is the repository for my course, Electron: Building Cross Platform Desktop Apps on LinkedIn Learning and Lynda.com.
Stars: ✭ 69 (-58.93%)
Mutual labels:  tutorial, macosx
Learning
Learning Shell,Python,Golang,System,Network
Stars: ✭ 161 (-4.17%)
Mutual labels:  macosx
Php To Golang
從 PHP 到 Golang 的筆記。
Stars: ✭ 166 (-1.19%)
Mutual labels:  tutorial
Js Primer
📖 JavaScript Primer - 迷わないための入門書
Stars: ✭ 2,068 (+1130.95%)
Mutual labels:  tutorial
Learnpythonforresearch
This repository provides everything you need to get started with Python for (social science) research.
Stars: ✭ 163 (-2.98%)
Mutual labels:  tutorial
Frameless Titlebar
Customizable Electron Titlebar for frameless windows
Stars: ✭ 167 (-0.6%)
Mutual labels:  menubar
Java Telegram Bot Tutorial
Java Telegram Bot Tutorial. Feel free to submit issue if you found a mistake.
Stars: ✭ 165 (-1.79%)
Mutual labels:  tutorial
An Idiots Guide To Installing Arch On A Lenovo Carbon X1 Gen 6
so you wanted to install arch huh
Stars: ✭ 165 (-1.79%)
Mutual labels:  tutorial
Elasticsearch Gmail
Index your Gmail Inbox with Elasticsearch
Stars: ✭ 1,964 (+1069.05%)
Mutual labels:  tutorial
Switching To Contracting Uk
A step by step guide of how to start contracting in United Kingdom
Stars: ✭ 2,024 (+1104.76%)
Mutual labels:  tutorial
D3tutorial
📊📈 A D3 v6 tutorial - interactive bar chart and multiple coordinated views (MCV)
Stars: ✭ 163 (-2.98%)
Mutual labels:  tutorial
Sassessentials
Repository for my tutorial course: Sass Essential Training on LinkedIn Learning and Lynda.com.
Stars: ✭ 167 (-0.6%)
Mutual labels:  tutorial
Haskell Scotty Realworld Example App
Exemplary real world backend API built with Haskell/Scotty https://realworld.io
Stars: ✭ 162 (-3.57%)
Mutual labels:  tutorial
Fetchcord
FetchCord grabs your OS info and displays it as Discord Rich Presence
Stars: ✭ 162 (-3.57%)
Mutual labels:  macosx
Cordova Create React App
A tutorial on how to set up a Cordova project using Create React App.
Stars: ✭ 167 (-0.6%)
Mutual labels:  tutorial

Mac OS X Application like a menu bar popup message

A simple tutorial which explains how to create Mac OS X application as a menu bar popup message.
Like that:

alt tag

For that, we need to create EventMonitor class for handling monitor events.

import Cocoa

open class EventMonitor {
	
	fileprivate var monitor: AnyObject?
	fileprivate let mask: NSEventMask
	fileprivate let handler: (NSEvent?) -> ()
	
	public init(mask: NSEventMask, handler: @escaping (NSEvent?) -> ()) {
		self.mask = mask
		self.handler = handler
	}
	
	deinit {
		stop()
	}
	
	open func start() {
		monitor = NSEvent.addGlobalMonitorForEvents(matching: mask, handler: handler) as AnyObject?
	}
	
	open func stop() {
		if monitor != nil {
			NSEvent.removeMonitor(monitor!)
			monitor = nil
		}
	}
}

And the example of AppDelegate:

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

	let statusItem = NSStatusBar.system().statusItem(withLength: -2)
	let popover = NSPopover()
	var eventMonitor: EventMonitor?

	func applicationDidFinishLaunching(_ aNotification: Notification) {
		
		if let button = statusItem.button {
			button.image = NSImage(named: "StatusBarButtonImage")
			button.action = #selector(AppDelegate.togglePopover(_:))
		}
		
		let mainViewController = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "ViewControllerId") as! ViewController
		
		popover.contentViewController = mainViewController
		
		eventMonitor = EventMonitor(mask: [.leftMouseDown, .rightMouseDown]) { [unowned self] event in
			if self.popover.isShown {
				self.closePopover(event)
			}
		}
		eventMonitor?.start()
	}

	func applicationWillTerminate(_ aNotification: Notification) {
	}

	func togglePopover(_ sender: AnyObject?) {
		if popover.isShown {
			closePopover(sender)
		} else {
			showPopover(sender)
		}
	}
	
	func showPopover(_ sender: AnyObject?) {
		if let button = statusItem.button {
			popover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
		}
		eventMonitor?.start()
	}
	
	func closePopover(_ sender: AnyObject?) {
		popover.performClose(sender)
		eventMonitor?.stop()
	}

}

It’s really simple and I think no sense to describe details, just see the code.

Full code of this example you can find in this repository.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].