App not quit when using ProcessMBS.quit

I need to quit an app. The following code has worked for years. Now I’ve got the second report that after executing the code the app is still running:

'try to quit the app
dim maxProcess as ProcessMBS = Utility.getProcess(theBundleID)
if maxProcess = Nil then Return ""
dim theResult as Integer = maxProcess.QuitProcess
if theResult <> 0 then
  Globals.theErrorLog.logitem(currentMethodName + " error: " + Str(theResult))
  Return Replace(kErrorQuit, "<<appname>>", AppCommon.getInstallationAppName)
end if

Thread.SleepCurrent(100)

'final check
maxProcess = Utility.getProcess(theBundleID)
if maxProcess <> Nil then
  Globals.theErrorLog.logitem(currentMethodName + " app not quit")
  Return Replace(kErrorQuit, "<<appname>>", AppCommon.getInstallationAppName)
end if

theResult is 0 and the session log has “app not quit” in it.

What can I do to quit the app? Xojo 2021r2.1. macOS Monterey

Is there any reason why you have to use MBS instead of the regular quit ?

I’m quitting not my own app but another one. And yes, I need to do that because it’s part of an installation.

I understand better. Could very well be the result of security tightening with Monterey.

If the other application is yours as well, perhaps you can use IPCSocket to send it a message so it quits.

2 Likes

Good idea.

QuitProcess basically sends an Apple Event.
No idea how long quitting takes, wether the OS blocks the event or the app ignores it.

IIRC, if you launch the application using a shell class or NSTask, you can also close it via that shell class/NSTask session.

You could also try using NSRunningApplications to send the terminate command to it.

1 Like