-3

How to detect if an application is launched with objective-c for mac?

lbwnb123
  • 35
  • 7
  • Please have a look on it. https://stackoverflow.com/questions/38971994/detect-if-the-application-in-background-or-foreground-in-swift – aBilal17 Mar 28 '18 at 13:13
  • 2
    @aBilal17 I'm not certain how the linked answer relates to this one. This question is about macOS, not iOS. (Also not certain why there are so many close and down votes; there's nothing wrong with this question and it has a very simple but non-obvious answer.) – Rob Napier Mar 28 '18 at 13:19

1 Answers1

2

"Is an application launched" can be somewhat subtle. It depends on exactly what kind of application it is, and the lines aren't always clear. That said, for the most common cases (and likely what you're looking for), use NSWorkspace:

NSArray *apps = [[NSWorkspace sharedWorkspace] runningApplications];

You can search through that to find the NSRunningApplication you care about. Typically the best property to use is bundleIdentifier.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610