Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkol5222/c8d6ee54651c9fa5160ddf1ea657cc06 to your computer and use it in GitHub Desktop.
Save mkol5222/c8d6ee54651c9fa5160ddf1ea657cc06 to your computer and use it in GitHub Desktop.
//
// 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