Question for a *SERIOUSLY HARDCORE* Mac programmer

glasspusher

Member
SoSH Member
Jul 20, 2005
9,973
Oakland California
Figured I'd ask here. Any of my few Mac programmer friends in my area can't answer my question.

Involves keeping a timer running accurately on a Mac app running in the background. Apple has, over the past few years, become maniacal about saving energy on their laptops, to the point of putting timers to sleep when apps are in the background, and I haven't paid enough attention in the past few years and missed it.

I have a kludge but would be interested (and impressed!) if anyone knows how to do this the "approved" way.
 

cgori

Member
SoSH Member
Oct 2, 2004
4,006
SF, CA
Figured I'd ask here. Any of my few Mac programmer friends in my area can't answer my question.

Involves keeping a timer running accurately on a Mac app running in the background. Apple has, over the past few years, become maniacal about saving energy on their laptops, to the point of putting timers to sleep when apps are in the background, and I haven't paid enough attention in the past few years and missed it.

I have a kludge but would be interested (and impressed!) if anyone knows how to do this the "approved" way.
Since they are Intel cpus, is this api supported?

https://www.intel.com/content/dam/www/public/us/en/documents/technical-specifications/software-developers-hpet-spec-1-0a.pdf

(Unfortunately not a Mac developer)
 

EricFeczko

Member
SoSH Member
Apr 26, 2014
4,823
Figured I'd ask here. Any of my few Mac programmer friends in my area can't answer my question.

Involves keeping a timer running accurately on a Mac app running in the background. Apple has, over the past few years, become maniacal about saving energy on their laptops, to the point of putting timers to sleep when apps are in the background, and I haven't paid enough attention in the past few years and missed it.

I have a kludge but would be interested (and impressed!) if anyone knows how to do this the "approved" way.
You could just disable the behavior across all or an individual app:

http://osxdaily.com/2014/05/13/disable-app-nap-mac-os-x/

Hope this helps.
 

glasspusher

Member
SoSH Member
Jul 20, 2005
9,973
Oakland California
Thanks- you pass the "seriously hardcore" test. I was looking for something a bit more high level in the OS's APIs. Right now I get things behaving my way by having a daemon ping my app whether it's in the background or not. macOS doesn't throttle daemons.
 

SumnerH

Malt Liquor Picker
Dope
SoSH Member
Jul 18, 2005
31,893
Alexandria, VA
Figured I'd ask here. Any of my few Mac programmer friends in my area can't answer my question.

Involves keeping a timer running accurately on a Mac app running in the background. Apple has, over the past few years, become maniacal about saving energy on their laptops, to the point of putting timers to sleep when apps are in the background, and I haven't paid enough attention in the past few years and missed it.

I have a kludge but would be interested (and impressed!) if anyone knows how to do this the "approved" way.
I think beginActivityWithReasons can be used to disable App Nap, which is what's messing with your timers. Unless things have changed since then (last time I looked at this was a couple years ago).

https://stackoverflow.com/questions/19847293/disable-app-nap-in-macos-10-9-mavericks-application
 

Blacken

Robespierre in a Cape
SoSH Member
Jul 24, 2007
12,152
Sumner has it - beginActivityWithReasons (and, as the SO answer notes, retaining the object so it can't get ARC'd from under you) is the magic bullet here.
 

glasspusher

Member
SoSH Member
Jul 20, 2005
9,973
Oakland California
Sumner has it - beginActivityWithReasons (and, as the SO answer notes, retaining the object so it can't get ARC'd from under you) is the magic bullet here.
I'm pretty sure I tried this one (been about 10 months) but since I'm not so much interested in an activity as a timer to fire consistently, doing this gives me the processor pig thing in Hello, Metronome! above, even from the command line.

Hello, Metronome! mentioned above is a processor pig in its own right. WTF, Apple?
 

glasspusher

Member
SoSH Member
Jul 20, 2005
9,973
Oakland California
If anyone thinks this a worthy task (whether in the background or not, get it?) to solve without it being an epic, PM me, there may be some compensation I'd give you for your trouble.