Stopping Mac going to Sleep

Hi All,

i’ve tried googling and cannot seem to find the answer i am after. Does XOJO support the ability to stop a MAC going into Sleep / HDD going to sleep. If it doesn’t are there any 3rd party plugins anyone can suggest. I have an app that runs for 3 hours, sometimes i forget to change the hibernate on a new machine and when i come back its killed the processes the app does and i have to start again.

Check NSProcessInfo and the beginActivity method there.

Via declares or plugins

See
http://www.monkeybreadsoftware.net/class-nsprocessinfombs.shtml

Thanks Christian,

I am looking at the example now, is it as simple as just calling the method in the Main app?

May be possible without plugins too via shell:
http://osxdaily.com/2012/08/03/disable-sleep-mac-caffeinate-command/

thanks Tim.

caffeinate maybe a way forward, is there a way to call the terminal app without having it show on screen, gain focus, type the command and then exit?

also looking at the arguments. if i had my app called SpecialK would the argument look like this:

caffeinate -SpecialK ? e.g does it check to see if the process is still running, and if not hen “de-caffeinates”

more JAVA???

Can you pass it with an embedded applescript under a SHELL command rather than load Terminal?

like this

do shell script "caffeinate -i '/Users/jbird/Desktop/specialapp.app'"

This should work…

In your app class, create a property called CaffeinateShell As Shell. In App.Open, do this:

dim sh as new Shell
sh.Mode = 2
sh.Execute "caffeinate"

CaffeinateShell = sh

Because it lives in the App class, the Shell will die when the app quits. As long as it’s running, the machine will stay awake.

See the man page for caffeinate if you want more specific options.

You may want to look at http://documentation.xojo.com/index.php/Shell

I offered caffeinate as a possible alternative to plugins, but I am not fully versed on Xojo Shell and it’s capabilities and limitations at this time.

Lastly, I would not call your app SpecialK. It is a known piracy/crack group, and their keygen icons look like the cereal with the same name.

for the NSProcessInfo, simply put a property in the app class:

activity as NSProcessInfoActivityMBS

than in app.open set it with:

#if TargetMacOS then dim ProcessInfo as NSProcessInfoMBS = NSProcessInfoMBS.processInfo Activity = ProcessInfo.beginActivity(NSProcessInfoMBS.NSActivityIdleSystemSleepDisabled, "Heavy Work") #endif

@Kem Tekinay

Thanks for the above, I must be doing something wrong

link text

link text

I’ve then set the following power settings

link text

I time 1min 10 seconds and mac goes to sleep

Ive then built the app and run it

i leave mac for 1 min 10 seconds.

It dims screen and goes to sleep.

The screen going to sleep is not important as apps will continue to run. Does the whole Mac go to sleep though?

If you want to prevent any type of sleep (not recommended for long term), use this:

caffeinate -u

I was going to use:

-i Create an assertion to prevent the system from idle sleeping.

rather than - u

thoughts

-i is default, I think.

with

dim sh as new Shell
sh.Mode = 2

sh.Execute “caffeinate -i”

CaffeinateShell = sh

it works like a charm :slight_smile:

with

[code] dim sh as new Shell
sh.Mode = 2

sh.Execute “caffeinate -i”

CaffeinateShell = sh[/code]

it works like a charm :slight_smile:

Cool.

The “App Nap” demo on this page uses the NSProcessInfo to disable system sleep, I accidentally specified the wrong argument.
http://ohanaware.com/xojo/

I once was tasked with troubleshooting a Windows PC not locking the screen after 15 minutes on a Domain bound PC, which violated our security policy. It transpired the user was running a “mouse jiggler” program that moved the mouse by 1 pixel at her defined intervals (14 minutes I suspect). Hated having to enter her password apparently. The single pixel movement was enough to keep the system awake, but completely invisible to the end user. Clever. but subsequently blacklisted :wink:

The developer did something like this I imagine.
(MBS plugin required)

dim x,y as integer dim p as PresskeyMBS p=new PresskeyMBS x=system.mousex y=system.mousey+1 // move one pixel down p.mousemove x,y
Stick it in a Timer Action event.
You’d need to check the value of y and move up rather than down if appropriate.
“caffeinated” only came in to being in 10.8, but this aught to work on any OS version or platform.

[quote=265138:@Jay maxted]I am looking at the example now, is it as simple as just calling the method in the Main app?
[/quote]

As said, you need to use NSProcessInfo (Sams example or using MBS).
You can place the code in the Apps open event but be sure the token property is GLOBAL. If not, it will kill the token property when the open event ends, thus it will not keep your app working when your system is sleeping.