I need to know which applications are running and have an active window. Something similar must be what's in the 'command + tab' hotkey switcher.
When I run some code like this:
NSWorkspace * ws = [NSWorkspace sharedWorkspace];
NSArray * apps = [ws runningApplications];
NSLog (@"%@", apps);
I get this in my log:
"<NSRunningApplication: 0x6080001052b0 (com.apple.loginwindow - 66)>",
"<NSRunningApplication: 0x608000105340 (com.apple.systemuiserver - 285)>",
"<NSRunningApplication: 0x6080001053d0 (com.apple.dock - 284)>",
"<NSRunningApplication: 0x608000105460 (com.apple.finder - 286)>",
"<NSRunningApplication: 0x6080001054f0 (com.apple.iTunesHelper - 339)>",
"<NSRunningApplication: 0x608000105580 (cc.omh.Clyppan - 340)>",
"<NSRunningApplication: 0x608000105610 (ws.agile.1PasswordAgent - 333)>",
"<NSRunningApplication: 0x6080001056a0 (com.irradiatedsoftware.Cinch-Direct - 342)>",
"<NSRunningApplication: 0x608000105730 (com.leapmotion.Leap-Motion - 343)>",
"<NSRunningApplication: 0x6080001057c0 (com.apple.notificationcenterui - 316)>",
"<NSRunningApplication: 0x608000105850 (com.smileonmymac.textexpander - 348)>",
"<NSRunningApplication: 0x6080001058e0 (com.lightheadsw.caffeine - 350)>",
"<NSRunningApplication: 0x608000105970 (2BUA8C4S2C.com.agilebits.onepassword4-helper - 309)>"
It's showing all running applications. I only want the applications that are running and visible in the Dock.
The members of the array returned by [NSWorkspace runningApplications]
are of type NSRunningApplication
. You want to pick out the ones whose activationPolicy
property has type NSApplicationActivationPolicyRegular
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With