Swift get running applications

Hi,


I am using: macOS Sierra and Swift3 in Command Line Tool

How can I get all the running applications into an array and than filter theme: if they have a UI and if they don't?

I am gueesing I have to use AppKit and SharedWorkspace somehow.

Replies

let running = NSWorkspace.shared().runningApplications


will get you the running applications, including those that have no currently visible UI. But I don't think you can find out if they "have a UI". Even if you find their bundle and looks for "NSUIElement=1" or similar, this only means that they don't *usually* show a window, or that they don't appear in the dock.

It doesn't return all the running _processes_, if that's what your asking.

So the real question is - what are you trying to do?

So the real question is - what are you trying to do?

Indeed. The other point I’d likely clarified is how you expect this to behalf in the presence of multiple users. Are you expecting to see the apps from all the logged in users? Or just a specific user? And, if tha latter, can you guarantee that your tool is run from that user’s context?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"