Giorgi
07/09/2023, 11:04 AMlet center = NSWorkspace.shared.notificationCenter
init() {
center.addObserver(forName: NSWorkspace.didLaunchApplicationNotification,
object: nil, // always NSWorkspace
queue: OperationQueue.main) { (notification: Notification) in
if let app = notification.userInfo?[NSWorkspace.applicationUserInfoKey] as? NSRunningApplication {
if app.bundleIdentifier == "com.apple.Terminal" {
// User just launched the Terminal app; should we be worried?
print("blah")
}
}
}
}
Giorgi
07/09/2023, 11:04 AMGiorgi
07/09/2023, 11:05 AMGijs van Veen
07/11/2023, 9:07 AMclass Sample {
private val center = NSWorkspace.sharedWorkspace.notificationCenter
init {
center.addObserverForName(NSWorkspaceDidLaunchApplicationNotification, null, NSOperationQueue.mainQueue) { notification ->
(notification?.userInfo.orEmpty()[NSWorkspaceApplicationKey] as? NSRunningApplication)?.let { app ->
when (app.bundleIdentifier) {
"com.apple.Terminal" -> {
// User just launched the Terminal app; should we be worried?
println("blah")
}
}
}
}
}
}
Giorgi
07/15/2023, 6:47 PM