Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7027645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:16:30+00:00 2026-05-28T00:16:30+00:00

My cocoa app runs background tasks, which I would like to stop when the

  • 0

My cocoa app runs background tasks, which I would like to stop when the user becomes idle (no keyboard/mouse input) and then resume when the user becomes active again. Is there a way to register for idle-state notifications?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:16:31+00:00Added an answer on May 28, 2026 at 12:16 am

    In case you can’t link to Carbon (ie. you want to compile x86_64 bit binary) you can wrap this function (which returns current idle time in seconds resolution as double – CFTimeInterval) in a timer:

    #include <IOKit/IOKitLib.h>
    
    CFTimeInterval CFDateGetIdleTimeInterval() {
        mach_port_t port;
        io_iterator_t iter;
        CFTypeRef value = kCFNull;
        uint64_t idle = 0;
        CFMutableDictionaryRef properties = NULL;
        io_registry_entry_t entry;
    
        IOMasterPort(MACH_PORT_NULL, &port);
        IOServiceGetMatchingServices(port, IOServiceMatching("IOHIDSystem"), &iter);
        if (iter) {
            if ((entry = IOIteratorNext(iter))) {
                if (IORegistryEntryCreateCFProperties(entry, &properties, kCFAllocatorDefault, 0) == KERN_SUCCESS && properties) {
                    if (CFDictionaryGetValueIfPresent(properties, CFSTR("HIDIdleTime"), &value)) {
                        if (CFGetTypeID(value) == CFDataGetTypeID()) {
                            CFDataGetBytes(value, CFRangeMake(0, sizeof(idle)), (UInt8 *) &idle);
                        } else if (CFGetTypeID(value) == CFNumberGetTypeID()) {
                            CFNumberGetValue(value, kCFNumberSInt64Type, &idle);
                        }
                    }
                    CFRelease(properties);
                }
                IOObjectRelease(entry);
            }
            IOObjectRelease(iter);
        }
    
        return idle / 1000000000.0;
    }
    

    You’ll need to link your code to IOKit.framework

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I create a Cocoa app that runs in the background (not in
In a OSX Cocoa app, I would like a button that would open the
I'm writing a Cocoa app which allows the user to drag content to another
I have a cocoa app with two types windows each of which requires a
I have created Cocoa app which is type of launch agent. To distribute this
I have a Cocoa app that embeds a WebView. I'd like to intercept a
I've developing a Cocoa app that has certain resources (images) which I wish to
I wrote a Cocoa app on my Mac which is 10.6.6. I sent it
I have a Cocoa app with an NSTextView control which holds its text in
I'm currently writing a Cocoa app that uses pdftotext from xpdf, which I personally

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.