Prevent App Nap

Is it possible do deactivate App Nap from code? So far all I have tried has failed. It looks like the only way is to check that ‘Prevent App Nap’ check box :-/

Detect? Your app is not running.

You can use our plugin with NSProcessInfoMBS class and use the beginActivity method there:
http://www.monkeybreadsoftware.net/class-nsprocessinfombs.shtml

Actually I meant that application checkbox, on the Finder ‘Get Info’ window labeled ‘Prevent App Nap’ on Maverick. It is deactivated by default. I would like to add something to my Xojo IDE build script to activate that. So far nothing seems to work. It seems it is a system setting :-/

From the apple developer website:

defaults write <app domain name> NSAppSleepDisabled -bool YES

Maybe this will do what you want? I haven’t actually tried it myself.

[quote=54752:@Jason King]From the apple developer website:

defaults write <app domain name> NSAppSleepDisabled -bool YES

Maybe this will do what you want? I haven’t actually tried it myself.[/quote]

I’ve tried that code before and it doesn’t seem to update anything in the Finder’s info window. I’ve used it when apps are both open and shut and it doesn’t give any errors but doesn’t change anything when opening the get info window.

Yes, same for me, I use that command in my build script and it does nothing… :-/

Maybe run it in the open event for the app? So it is “redisabled” every time the app is opened?

From the apple Docs:

[quote]To support activities that should not be suspended, the NSProcessInfo class has three new methods—beginActivityWithOptions:reason:, endActivity:, and performActivityWithOptions:reason:block:—to tell OS X that your app is actively doing something important. These methods do two things:

Allow your app to temporarily suspend idle sleep, display sleep, sudden termination, and automatic termination for the duration of a particular operation
Allow your app to temporarily increase the scheduler timer precision while your app is performing latency-critical operations
[/quote]

Right so, because In a build script you could only affect your own preference settings. The “defaults” command would need to be executed on the user’s Mac that runs your app. Therefore, if that command works at all, you’d have to issue it in code from your app when it starts. Since this is an app preference, using macoslib, calling CFPreferences.Value(“NSAppSleepDisabled”)=true should do it.

Nope, that doesn’t seem to make a difference. Is the terminal command

defaults write NSAppSleepDisabled -bool YES

correct at all? Because it does nothing.

Just for giggles I checked some apps in the applications folder and none has “Prevent App Nap” selected. I simply enabled the setting for one app. And neither info.plist nor prefs.plist showed any change.