Search code examples
macosswift3macos-sierra

Best way to sort through running apps that have UI | Swift3, macOS


So I have an app that analyses the running apps, my code so far

func running() -> [NSRunningApplication]{
    let base = NSWorkspace()
    let apps = base.runningApplications
    return apps
}

for app in running() {
    print(app.localizedName)
    print("isActive: \(app.isActive) | isHidden: \(app.isHidden) | ")

}

I can determine lots of properties properties. However I want to filter apps that have UI kind of like the ones in the Force Quit Applications menu:fca menu

So any tips on how to filter these apps?


Solution

  • Filter for activationPolicy == .regular

    let apps = base.runningApplications.filter {$0.activationPolicy == .regular}
    

    Source: NSApplicationActivationPolicy