Always keep my program active even when other programs are running

Hi All.

A memory check here.
I remember, or think I remember, that it was possible to keep my program (running on a Mac) active, even if another program was running.

For some reason I think there was an option to do so.

Is my memory failing me.

Regards

App.AllowAutoQuit controls whether your application automatically quits or not when it loses active status. Check what your setting is, the default varies by platform (true on Windows*, false on macOS).

You’d have to take note of your app being deactivated and reactivate it. But this is a fairly user-hostile thing to do. What’s your motivation?

Maybe you’re talking about AppNap which make your app runs slower when it is not front ?

An app running in the background shouldn’t quit or stop working, at least not on a Mac. What issue are you seeing?

You may also be thinking of a Global Floating Window which would be in front of all other windows even if your app was not.

Hi Ian.

I think I know what the “problem” is.
The program runs fine, but when the computer powers down at the end of my screensaver time, the “updates” (showing date and time, etc) stop. I log back in and the program continues to run normally.

So it has to do with my computer “sleeping” I guess.

Maybe I have to have some “thread” to keep it “alive”?

Regards

There is a command line program called “caffeinate”, which prevents sleep, you could try running that in a shell. I know that there was a library somewhere that did the same thing as “caffeinate”, but I can’t remember the details.

Hi Ian.

Caffinate was always my plan b… but was hoping for other options

Thanks for your time.

Regards

If you have access to MBS plugins you can use IOPMAssertionMBS to accomplish the same thing natively in your application.

If you know how to write declares (I’m no help there) then I’m sure you can accomplish the same thing.

preventSystemSleep = new IOPMAssertionMBS(IOPMAssertionMBS.kIOPMAssertionTypePreventUserIdleSystemSleep, IOPMAssertionMBS.kIOPMAssertionLevelOn, "Continuous image display")
preventDisplaySleep = new IOPMAssertionMBS(IOPMAssertionMBS.kIOPMAssertionTypePreventUserIdleDisplaySleep, IOPMAssertionMBS.kIOPMAssertionLevelOn, "Continuous image display")

Those properties just can’t go out of scope while your application is running.

1 Like

I would prevent App Nap with using beginActivity in NSProcessInfoMBS class.

There you can prevent system sleep or just display sleep.

e.g.

Var Activity as NSProcessInfoActivityMBS // property in your window, control, thread, app
Var AllowAppNap as boolean // allow or not?

Var ProcessInfo as NSProcessInfoMBS = NSProcessInfoMBS.processInfo
if AllowAppNap then
  Activity = nil
else
  // disable sleep to let us make something...
  Activity = ProcessInfo.beginActivity(NSProcessInfoMBS.NSActivityBackground, "Backup running")
end if