Ideal way to single-instance apps on the Mac

后端 未结 5 1691
野趣味
野趣味 2020-12-06 03:18

On Windows, it\'s common practice to create a named mutex and use the presence of that to determine that an instance of a given app is already running. This has its drawback

5条回答
  •  余生分开走
    2020-12-06 03:40

    To elaborate further on using NSWorkspace. Try using 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.

提交回复
热议问题