I would like to know with Swift, if my macOS app is running in the background of in foreground.
I found different ways (for example here: Is there any way to check if iOS app is in background? ) related to iOS apps, but not for modern macOS.
It would be great if there was also for macOS a way similar to this one:
let state = NSApplication.applicationState
if state == .background { // doesn't work
// do something here
}