Skip to content

Instantly share code, notes, and snippets.

@karl-gustav
Last active February 8, 2024 11:42
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 karl-gustav/ac76fe7751e01b5384abfdd7a3b7e951 to your computer and use it in GitHub Desktop.
Save karl-gustav/ac76fe7751e01b5384abfdd7a3b7e951 to your computer and use it in GitHub Desktop.
Listening for macOS wakeup events
JIT session error: Symbols not found: [ _OBJC_CLASS_$_NSWorkspace, _NSWorkspaceDidWakeNotification ]
Failed to materialize symbols: { (main, { __swift_FORCE_LOAD_$_swiftObjectiveC_$_watch_for_lock_unlock, _got.$sSY8rawValuexSg03RawB0Qz_tcfCTq, _$sSo18NSNotificationNameaSYSCMA, __swift_FORCE_LOAD_$_swiftos_$_watch_for_lock_unlock, _got.$s8RawValueSYTl, _got.$ss20_SwiftNewtypeWrapperPSYTb, _$s10Foundation12NotificationVIeghn_So14NSNotificationCIeyBhy_TR, _symbolic _____ 21watch_for_lock_unlock18ScreenLockObserverC, _got.$ss20_SwiftNewtypeWrapperMp, _$s21watch_for_lock_unlock18ScreenLockObserverCMn, _$sSo18NSNotificationNameaABSYSCWL, _$s21watch_for_lock_unlock18ScreenLockObserverCMm, _got.$s15_ObjectiveCTypes01_A11CBridgeablePTl, _associated conformance So18NSNotificationNameaSHSCSQ, _associated conformance So18NSNotificationNameas20_SwiftNewtypeWrapperSCSY, _$sSo18NSNotificationNameaABs35_HasCustomAnyHashableRepresentationSCWl, _$sSo18NSNotificationNameas20_SwiftNewtypeWrapperSCMc, _$sS2Ss21_ObjectiveCBridgeable10FoundationWl, _$sSo18NSNotificationNameaABs35_HasCustomAnyHashableRepresentationSCWL, _$sSo18NSNotificationNameaABSHSCWL, _$sSo18NSNotificationNameas21_ObjectiveCBridgeableSCMc, _$sSo18NSNotificationNameaSQSCMc, _$sSo18NSNotificationNameaSHSCMc, _got.$ss21_ObjectiveCBridgeableP09_bridgeToA1C01_A5CTypeQzyFTq, _$sSo18NSNotificationNameas21_ObjectiveCBridgeableSCMA, _got.$sSH13_rawHashValue4seedS2i_tFTq, _got.$ss20_SwiftNewtypeWrapperPs35_HasCustomAnyHashableRepresentationTb, _got.$sSH4hash4intoys6HasherVz_tFTq, _got.$ss35_HasCustomAnyHashableRepresentationP03_tobcD0s0cD0VSgyFTq, _$sSo18NSNotificationNameaABs20_SwiftNewtypeWrapperSCWl, _$sSo18NSNotificationNameaABSQSCWL, _$sSo18NSNotificationNameaSQSCSQ2eeoiySbx_xtFZTW, _$sSo18NSNotificationNameas35_HasCustomAnyHashableRepresentationSCMc, _got.$ss35_HasCustomAnyHashableRepresentationMp, _got.$ss21_ObjectiveCBridgeableP016_forceBridgeFromA1C_6resulty01_A5CTypeQz_xSgztFZTq, _got.$sSY8rawValue03RawB0QzvgTq, _$sSo18NSNotificationNameaSYSCMc, _$sSo18NSNotificationNameaSHSCSH13_rawHashValue4seedS2i_tFTW, _main, _$sSo18NSNotificationNameaSHSCSH4hash4intoys6HasherVz_tFTW, _$sSo18NSNotificationNameaSHSCSH9hashValueSivgTW, __swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers_$_watch_for_lock_unlock, _$sSo18NSNotificationNameaSYSCSY8rawValue03RawD0QzvgTW, _$ss7CVarArg_pMD, _$sSo18NSNotificationNameaSYSCSY8rawValuexSg03RawD0Qz_tcfCTW, _symbolic So8NSStringC, _$s21watch_for_lock_unlock18ScreenLockObserverCfd, $.watch_for_lock_unlock.__inits.0, _$s21watch_for_lock_unlock18ScreenLockObserverCACycfc, _$sS2Ss21_ObjectiveCBridgeable10FoundationWL, _symbolic ______p s7CVarArgP, _got.$ss21_ObjectiveCBridgeableP024_conditionallyBridgeFromA1C_6resultSb01_A5CTypeQz_xSgztFZTq, _$s21watch_for_lock_unlock18ScreenLockObserverCfD, _$s21watch_for_lock_unlock18ScreenLockObserverCACycfC, _$s21watch_for_lock_unlock18ScreenLockObserverCMa, _$sSo6NSTaskCML, _got.$sSQMp, ___swift_instantiateConcreteTypeFromMangledName, _$sSoMXM, _got.$sSHMp, _got.$sSHSQTb, _$s10FoundationMXM, _symbolic $sSY, _got.$sSYMp, _$sSo6NSTaskCMa, __swift_FORCE_LOAD_$_swiftCoreFoundation_$_watch_for_lock_unlock, _symbolic SS, _$sSo18NSNotificationNameaMn, __swift_FORCE_LOAD_$_swiftXPC_$_watch_for_lock_unlock, __swift_FORCE_LOAD_$_swiftDarwin_$_watch_for_lock_unlock, _$sSo18NSNotificationNameaMa, __swift_FORCE_LOAD_$_swiftDispatch_$_watch_for_lock_unlock, _got.$ss21_ObjectiveCBridgeableMp, __swift_FORCE_LOAD_$_swiftIOKit_$_watch_for_lock_unlock, _$ss27_finalizeUninitializedArrayySayxGABnlF, __swift_FORCE_LOAD_$_swiftFoundation_$_watch_for_lock_unlock, __swift_FORCE_LOAD_$_swiftOSLog_$_watch_for_lock_unlock, _$sSa12_endMutationyyF, _$sSo18NSNotificationNamea8rawValueSSvg, __swift_FORCE_LOAD_$_swiftCoreGraphics_$_watch_for_lock_unlock, _associated conformance So18NSNotificationNameas20_SwiftNewtypeWrapperSCs35_HasCustomAnyHashableRepresentation, _$sSo18NSNotificationNameaMF, __swift_FORCE_LOAD_$_swiftMetal_$_watch_for_lock_unlock, _$sSo18NSNotificationNameas21_ObjectiveCBridgeableSCsACP026_unconditionallyBridgeFromC1Cyx01_C5CTypeQzSgFZTW, _$sSo18NSNotificationNameaMB, __swift_FORCE_LOAD_$_swiftCoreImage_$_watch_for_lock_unlock, __swift_FORCE_LOAD_$_swiftQuartzCore_$_watch_for_lock_unlock, _$sSo18NSNotificationNameaML, _$sSo18NSNotificationNameas21_ObjectiveCBridgeableSCsACP016_forceBridgeFromC1C_6resulty01_C5CTypeQz_xSgztFZTW, _$sSo18NSNotificationNameas21_ObjectiveCBridgeableSCsACP09_bridgeToC1C01_C5CTypeQzyFTW, _$sSo18NSNotificationNameaMf, _$s21watch_for_lock_unlock18ScreenLockObserverCACycfCTq, _$sSo18NSNotificationNameaABs20_SwiftNewtypeWrapperSCWL, _got.$ss21_ObjectiveCBridgeableP026_unconditionallyBridgeFromA1Cyx01_A5CTypeQzSgFZTq, _$s21watch_for_lock_unlock18ScreenLockObserverC4bash33_6169EBFFC084D1F8A8755F4D32AFBDBBLL3cmdySS_tF, ___swift_destroy_boxed_opaque_existential_0, _$s21watch_for_lock_unlock18ScreenLockObserverCN, _got.$sSQ2eeoiySbx_xtFZTq, ___swift_project_boxed_opaque_existential_0, _got.$ss7CVarArgMp, _symbolic $ss21_ObjectiveCBridgeableP, _got.$sSH9hashValueSivgTq, _symbolic _____ So18NSNotificationNamea, _$sSo18NSNotificationNameaABSQSCWl, _$sSo18NSNotificationNamea8rawValueABSS_tcfC, _$sSo18NSNotificationNameaABSYSCWl, _$sSo6NSTaskCABycfcTO, _$sSo18NSNotificationNameas21_ObjectiveCBridgeableSCsACP024_conditionallyBridgeFromC1C_6resultSb01_C5CTypeQz_xSgztFZTW, _$s21watch_for_lock_unlockMXM, _$sSo18NSNotificationNameaABSHSCWl, _$sSo6NSTaskCABycfC, _$sSo18NSNotificationNameas35_HasCustomAnyHashableRepresentationSCsACP03_todeF0s0eF0VSgyFTW }) }
#!/usr/bin/env swift
import Foundation
import AppKit
class ScreenLockObserver {
init() {
let dnc = DistributedNotificationCenter.default()
let nc = NotificationCenter.default
let wnc = NSWorkspace.shared.notificationCenter
// listen for screen lock
let _ = dnc.addObserver(forName: NSNotification.Name("com.apple.screenIsLocked"), object: nil, queue: .main) { _ in
NSLog("Screen Locked")
}
// listen for screen unlock
let _ = dnc.addObserver(forName: NSNotification.Name("com.apple.screenIsUnlocked"), object: nil, queue: .main) { _ in
NSLog("Screen Unlocked")
}
let _ = dnc.addObserver(forName: NSNotification.Name("com.apple.screensaver.didstart"), object: nil, queue: .main) { _ in
NSLog("Screensaver did start")
}
let _ = dnc.addObserver(forName: NSNotification.Name("com.apple.screensaver.didstop"), object: nil, queue: .main) { _ in
NSLog("Screensaver did stop")
}
// listen for wakeup
let _ = nc.addObserver(forName: NSNotification.Name("systemDidWake"), object: nil, queue: .main) { _ in
NSLog("Wake up")
}
// listen for wakeup 2
let _ = wnc.addObserver(forName: NSWorkspace.didWakeNotification, object: nil, queue: .main) { _ in
NSLog("Wake up2")
}
RunLoop.main.run()
}
}
let _ = ScreenLockObserver()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment