Skip to content

Instantly share code, notes, and snippets.

@Akemi
Last active January 22, 2020 13:52
Show Gist options
  • Save Akemi/0c124a4a3eb4f28a2132be7dc3fae91b to your computer and use it in GitHub Desktop.
Save Akemi/0c124a4a3eb4f28a2132be7dc3fae91b to your computer and use it in GitHub Desktop.
touch bar NSSliderTouchBarItem problem
import Cocoa
extension NSTouchBarItem.Identifier {
static let sliderTest = NSTouchBarItem.Identifier("test.bar.slider")
}
extension NSTouchBar.CustomizationIdentifier {
static let testBar = NSTouchBar.CustomizationIdentifier("test.bar")
}
class App: NSApplication, NSApplicationDelegate, NSTouchBarDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
NSApp.setActivationPolicy(.regular)
atexit_b { NSApp.setActivationPolicy(.prohibited) }
NSApp.activate(ignoringOtherApps: true)
}
override func makeTouchBar() -> NSTouchBar? {
let touchBar = NSTouchBar()
touchBar.delegate = self
touchBar.customizationIdentifier = .testBar
touchBar.defaultItemIdentifiers = [.sliderTest]
touchBar.customizationAllowedItemIdentifiers = [.sliderTest]
return touchBar
}
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
switch identifier {
case NSTouchBarItem.Identifier.sliderTest:
let tbItem = NSSliderTouchBarItem(identifier: identifier)
tbItem.customizationLabel = "test";
return tbItem;
default:
return nil
}
}
}
let app = App.shared
NSApp = app
app.delegate = app as? NSApplicationDelegate
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment