Skip to content

Commit 285fb1f

Browse files
committed
added sleep button
1 parent 1e07dee commit 285fb1f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

MTMR/TouchBarController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
6161
NSTouchBar.minimizeSystemModalFunctionBar(touchBar)
6262
}
6363

64+
@objc func goToSleep() {
65+
let task = Process()
66+
task.launchPath = "/usr/bin/pmset"
67+
task.arguments = ["sleepnow"]
68+
task.launch()
69+
}
70+
6471
func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
6572
switch identifier {
6673
case .escButton:
@@ -84,6 +91,11 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
8491
let url = Bundle.main.url(forResource: "weather", withExtension: "scpt")!
8592
let script = try! String.init(contentsOf: url)
8693
return AppleScriptTouchBarItem(identifier: identifier, appleScript: script, interval: 600)
94+
95+
case .sleep:
96+
let item = NSCustomTouchBarItem(identifier: identifier)
97+
item.view = NSButton(title: "☕️", target: self, action: #selector(goToSleep))
98+
return item
8799

88100
case .prev:
89101
return CustomButtonTouchBarItem(identifier: identifier, title: "", HIDKeycode: NX_KEYTYPE_PREVIOUS)

0 commit comments

Comments
 (0)