Search code examples
cocoamacosmutex

Ideal way to single-instance apps on the Mac


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 drawbacks, but mostly works.

I can think of a ways to do this on the Mac:

  1. named pthread mutexes
  2. enumerate running processes and look for one that matches
  3. create and lock a file

Is there something built into Cocoa/Carbon that's easier than the options above? If not, which of the three are most used on the mac? I would assume 2 or 3...


Solution

  • Macs do not have instances in the same way as Windows does. Generally speaking you want the application running twice you physically need to copy the binary and then double click on the copied version as well.

    If you need two instances of an application running then you are not thinking like a Mac user :).

    Edit: This is technically not true. Check the comments.