Created
February 14, 2017 07:36
-
-
Save banjun/f4a13a6d3e850304047265a37dc74753 to your computer and use it in GitHub Desktop.
add Touch Bar support for CLI without .app bundle nor Info.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppDelegate: NSResponder, NSTouchBarDelegate, NSApplicationDelegate { | |
@available(OSX 10.12.2, *) | |
lazy var touchbar: NSTouchBar = { | |
let tb = NSTouchBar() | |
tb.delegate = self | |
tb.defaultItemIdentifiers = [NSTouchBarItemIdentifier(rawValue: "test")] | |
return tb | |
}() | |
@available(OSX 10.12.2, *) | |
override func makeTouchBar() -> NSTouchBar? { | |
return touchbar | |
} | |
@available(OSX 10.12, *) | |
lazy var touchbarLabel: NSTextField = NSTextField(labelWithString: "") | |
@available(OSX 10.12.2, *) | |
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItemIdentifier) -> NSTouchBarItem? { | |
let item = NSCustomTouchBarItem(identifier: identifier) | |
item.view = touchbarLabel | |
return item | |
} | |
} | |
let appDelegate = AppDelegate() | |
let app = NSApplication.shared() | |
app.setActivationPolicy(.regular) | |
app.delegate = appDelegate | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment