How to detect whether an OS X application is already launched

前端 未结 9 1605
自闭症患者
自闭症患者 2020-12-14 02:46

Normally an application bundle on OS X can only be started once, however by simply copying the bundle the same application can be launched twice. What\'s the best strategy t

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 02:51

    As has already been mentioned Cocoa applications do not usually allow you to run more than one instance at a time.

    In general, a cocoa way to solve this look at launchedApplications in NSWorkspace. This returns an NSArray containing a dictionary for each launched application. You can loop through the array to see if the app you are looking for is already running. I would advise that you use the value with the key NSApplicationBundleIdentifier which will have a value like "com.mycompany.myapp" rather than looking for the name. If you need to find the bundle identifier for an app you can look at its info.plist file in the app package.

提交回复
热议问题