Skip to content

Commit

Permalink
added sleep button
Browse files Browse the repository at this point in the history
  • Loading branch information
Toxblh committed Apr 9, 2018
1 parent 1e07dee commit 285fb1f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions MTMR/TouchBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
NSTouchBar.minimizeSystemModalFunctionBar(touchBar)
}

@objc func goToSleep() {
let task = Process()
task.launchPath = "/usr/bin/pmset"
task.arguments = ["sleepnow"]
task.launch()
}

func touchBar(_ touchBar: NSTouchBar, makeItemForIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem? {
switch identifier {
case .escButton:
Expand All @@ -84,6 +91,11 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
let url = Bundle.main.url(forResource: "weather", withExtension: "scpt")!
let script = try! String.init(contentsOf: url)
return AppleScriptTouchBarItem(identifier: identifier, appleScript: script, interval: 600)

case .sleep:
let item = NSCustomTouchBarItem(identifier: identifier)
item.view = NSButton(title: "☕️", target: self, action: #selector(goToSleep))
return item

case .prev:
return CustomButtonTouchBarItem(identifier: identifier, title: "", HIDKeycode: NX_KEYTYPE_PREVIOUS)
Expand Down

0 comments on commit 285fb1f

Please sign in to comment.