Created
January 15, 2021 05:34
-
-
Save keng42/46d5850366fd1946ceba0e1df5b5cf92 to your computer and use it in GitHub Desktop.
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
// | |
// main.swift | |
// Shell Notification Center | |
// | |
// Created by Keng Lee on 2021/1/15. | |
// | |
import Foundation | |
import Combine | |
var bag = Set<AnyCancellable>() | |
let dnc = DistributedNotificationCenter.default() | |
func shell(_ n: Notification) { | |
let task = Process() | |
task.launchPath = "/bin/zsh" | |
task.arguments = ["/Users/keng42/.shnc/main.sh", n.name.rawValue] | |
task.launch() | |
} | |
let events = [ | |
"com.apple.screenIsLocked", | |
"com.apple.screenIsUnlocked", | |
"com.apple.screensaver.didstart", | |
"com.apple.screensaver.willstop", | |
"com.apple.screensaver.didstop", | |
] | |
events.forEach { ev in | |
dnc.publisher(for: Notification.Name(rawValue: ev)) | |
.sink(receiveValue: shell) | |
.store(in: &bag) | |
} | |
print("Shell Notification Center Started") | |
// keepalive | |
dispatchMain() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment