I'm using the following Swift code to limit my GUI app on macOS to a single instance:
func IsAnotherInstanceRunning() -> Bool
{
let thisApp = NSRunningApplication.current
let thisBundleID = thisApp.bundleIdentifier
let thisPID = thisApp.processIdentifier
let workspace = NSWorkspace.shared
let apps = workspace.runningApplications.filter { (app) -> Bool in
if(app.bundleIdentifier == thisBundleID &&
app.processIdentifier != thisPID)
{
return true;
}
return false;
};
//Found any?
if(apps.count > 0)
{
return true
}
return false
}
I also have a console application written in C++. How can I do the same in pure C++?
Mainly how do I call anything related to NSRunningApplication
and NSWorkspace
?