Mavericks is putting my app to sleep

I have an application that does a lot of processing (creating Sudoku puzzles). However I am finding that Mavericks is suspending my application, even though the computer is “awake” and processing other apps. I presume that this is part of the much-lauded power saving features in Mavericks.

Does anyone know how I can stop Mavericks from suspending my app please?

Get Info on the app and theres a check box to disable app nap for that app

Or you can add a key to the apps plist to disable it for that app

From all that I’ve read you can’t disable it indefinitely as a developer. A user would have to tick the checkbox in finder.

Apple says [quote]Note: If you experience problems with App Nap, you can temporarily disable it for a particular process by typing:
defaults write NSAppSleepDisabled -bool YES[/quote]
but I can’t seem to track down this key you can add to Info.plist - I would love to be corrected on this one!

you can basically run that command after a build and insert it into your apps plist with that same command

defaults write NSAppSleepDisabled -bool YES

and this will insert it

Or you can write this into the plist

And I think there’s a direct API call you can make on NSProcessInfo (not sure if this has found its way into MacOSLib yet or not)

I thought that this was a preferences key, not a plist key?

Maybe the op can try both?

How are you doing the computing, from a thread or a timer?

I’ve tried both the key and the shell command, and neither seem to successfully disable app nap. It will still appear unchecked in the Finder if you go to the Get Info window. Seems the only way that actually works is to have to tell your users to manually check “Prevent App Nap.”

However, once checked, it seems to remember the setting even when a new version is installed.

There’s another thread on this here:

[quote=78332:@Sam Rowlands]I thought that this was a preferences key, not a plist key?
actually you’re right
as long as the prefs file is named in reverse dns form as recommended you should be able to use the defaults write version

for xojo it would be
defaults write com.xojo.xojo NSAppSleepDisabled -bool YES

[quote=78338:@Norman Palardy]actually you’re right
as long as the prefs file is named in reverse dns form as recommended you should be able to use the defaults write version

for xojo it would be
defaults write com.xojo.xojo NSAppSleepDisabled -bool YES[/quote]

Right that is what we’re told is correct way to do it. But if you actually run the command in terminal and then go to check if it worked in the Finder via the Get Info window, nothing changes and App Nap still happens.

There must be something else that needs to change for it to properly disable app nap. I’m guessing Apple doesn’t want apps programmatically disabling App Nap.

Just because you don’t see the checkbox checked in the Finder doesn’t mean that App Nap isn’t disabled. Start up your app and check Activity Monitor - I believe it has a column that indicates whether App Nap is enabled for a particular process.

Right that column will show whether or not it’s currently napping. In my testing, and in reports from my users, it always shows that if the Finder box isn’t checked, it will still nap.

I’ve tested it here with Preview and you can see it’s still napping:

Maybe you need to enable Developer Mode, because it certainly is working for me.

Looks like I’ve sparked an interesting discussion here. Thanks to all who have responded.

As the app in question is one I wrote for my own use Norman P’s initial reply is the one that I really needed. Thanks Norman, I appreciate that especially as the solution was right under my nose all the time! The activity in question just runs in a single main thread of a desktop app.

I had been toying with putting in another thread with some regular dumbo activity on a timer just to keep it going, as another timer driven app of mine keeps on going as I would wish. But I’m not quite sure what internal program activity is needed to create this effect. The program that doesn’t nap reads a URL every 60 seconds, processes the incoming stream and then writes selected data to a database server, but I’m not quite sure which of these activities is the one that keeps the app awake.

I am watching with interest the discussion about a technical solution for keeping a distributed app awake. Thanks.


Having a screenshot where it isn’t currently napping doesn’t necessarily prove that it won’t nap. :slight_smile: But you might have a point that it could be related to developer mode.

The problem is that I can’t ask all of my users to enter developer mode just so that my app won’t App Nap on their machines. So the general answer is that there is no way (that I’ve seen yet) to programmatically disable app nap for a distributed application.

A few things:

  • When using the ‘defaults’ command like this, you need to specify the full path to the application’s info.plist. Otherwise, your settings will land in the default domain.
  • You would need to restart the application after making this change.

If you check “Prevent App Nap” on the application, it never actually writes the key to the preferences file…

What happens when your application goes into nap?

I have an application that runs as a background task, admittedly it doesn’t do any processing until it receives a notification from the OS, but I’ve not seen App Nap cause any degradation to when this application is actually doing something… Because it doesn’t have a GUI until it’s needs one, Activity monitor says it’s pretty much napping all the time (which I’m quite happy with).

I noticed that. That’s why I feel there’s another field somewhere that Apple uses for app nap in addition to (or instead of) NSAppSleepDisabled.

The app does background networking and periodic syncing and several other tasks that all stop when App Nap happens.

In the screenshot I posted the path was That’s the full path, right?

Yep. Closed the app, ran the command, re-opened. Still naps.

Oh crap!..

I think you’re going to have to watch the following video… then select “Improving Power Efficiency with App Nap”.

Try this…

[quote]Applications may be opted out of App Nap automatically based on their application type. Currently, only applications which can become the frontmost app are eligible. This behavior may change in the future. If you have an application which is LSUIElement or LSBackgroundOnly, you can opt your application in to App Nap by setting the NSSupportsAppNap key in your Info.plist to be a Boolean type with a value of YES. A value of NO is ignored for all applications.

If your application shows a user interface, then the system will use the application visibility and other heuristics to move your application in and out of App Nap automatically. If your app does background work at various times but shows no UI, it can use the User Activities API to inform the system when it is appropriate for it to be eligible for App Nap.[/quote]