Forked from keng42/macos-shell-notification-center.swift
Created
February 9, 2024 10:43
-
-
Save mkol5222/c8d6ee54651c9fa5160ddf1ea657cc06 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