Skip to content

Instantly share code, notes, and snippets.

@banjun
Created February 14, 2017 07:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banjun/f4a13a6d3e850304047265a37dc74753 to your computer and use it in GitHub Desktop.
Save banjun/f4a13a6d3e850304047265a37dc74753 to your computer and use it in GitHub Desktop.
add Touch Bar support for CLI without .app bundle nor Info.plist
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