Created
July 31, 2021 17:35
-
-
Save Sam0230/9eac9250ba6a1570a4defb5d0966d415 to your computer and use it in GitHub Desktop.
Monitoring lock / unlock on macOS.
This file contains hidden or 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
// import Foundation; | |
import UserNotifications; | |
let dnc = DistributedNotificationCenter.default(); | |
let lockObserver = dnc.addObserver(forName: .init("com.apple.screenIsLocked"), object: nil, queue: .main) { _ in | |
print("lock"); | |
exit(0); | |
}; | |
let unlockObserver = dnc.addObserver(forName: .init("com.apple.screenIsUnlocked"), object: nil, queue: .main) { _ in | |
print("unlock"); | |
exit(0); | |
}; | |
RunLoop.main.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment