Hello, it possible to call a code to stop the mac from sleeping within a window (ie a checkbox value), but more specifically, will this stop the screen from dimming? And then another code to return the back to original state (undo it).
I’ve seen this thread below: And tried both methods (MBS / Caffeinate). I’ve got it compile, and asked chatgpt for advice, but it doesn’t seem to work. Apple website seems to suggest that caffeinate will stop screen dimming. Is it because I am trying to alter states within the app? and not on app.openening?
It’s difficult to debug this at my end, because I am having to compile on windows and then transfer to my mac to run (my macos too old to run XOJO). So if anybody could explain to like I am five how this could be achieved, I would be grateful.
Technically, it is possible to do that, but NOT with native Xojo code.
You need to use NSProcessInfo.beginActivity(options:reason:)
The options you want are NSActivityUserInitiated | NSActivityIdleDisplaySleepDisabled
This will tell the system that your app wants the second highest performance (the first is reserved for games) and that your app wants the screen to stay on. However, you need to understand that you’re only telling the system what you want, and it may choose to do something else.
You also need to tell the system when you’re done, you’d be surprised how many developers, even from big brands forget to do this.
You can check that it is working as expected by using Sleep Aid, as this will list out processes that are preventing sleep.
I wrote the declares for this some time ago and included it in my now discontinued App Kit, or you can probably use a certain plugin.
If you’re familiar with Objective-C or Swift, you can also write your own plugin or helper process to do this for you.
You’re over-complicating things. Use the Remote Debugger Desktop application. Just download Xojo on your Mac (you don’t need to actually run Xojo, but need to copy it in your Applications folder) then, go in Xojo’s Folder→Extras→Remote Debugger Desktop and launch “Remote Debugger Desktop.app”. Finally, in the Windows’ Xojo app, you can run/debug remotely (look inside the “Project” menu to set it up for the first time).
Keeping the screen awake, prevents System sleep. However preventing system sleep doesn’t keep the screen awake.
The second option is NOT recommended, because modern Macs have no state indicator, and so the user can believe that the Mac is sleeping, when in fact it’s actually doing Machine Learning for Apple…
Thanks so much everyone for your responses. The MBS OPMAssertionMBS test example was was the perfect solution for me. The remote debugger tip is great, but unfortunately it doesn’t seem to work as my mac is 10.11.6 and it still says it wants 10.14 when debugging remotely even though my app min version is set to 10.11.6 and works directly from the mac.