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 9265861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:10:53+00:00 2026-06-18T14:10:53+00:00

I have been trying to figure out how to create an OS X routine

  • 0

I have been trying to figure out how to create an OS X routine in objective C that:

  • run in the background (separate thread) and

  • repeatedly (timed or when certain criteria are met) captures several defined subsets of a specified window/screen (i.e. without user interaction) and

  • save the images into a specified path.

Similar the output of a “pre-programmed loop of cmd-shift-4 + mouseDown-drag”.

Neither SonofGrab nor ScreenSnapshot from Mac Developer Library seem to indicate how this could be done, but I suspect CGImageRef is one/the(?) way to go about it.

  1. Does anyone know how to do it?

  2. Are there other possible ways besides CGImageRef to solve this problem? Could it for example be done via command-line tools and NSTask?

  3. If so, what are the advantages/disadvantages with the different methods in terms of speed and complexity?

  • 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-06-18T14:10:54+00:00Added an answer on June 18, 2026 at 2:10 pm

    Assuming you have the logic required to do a screengrab (which you can see in SonOfGrab), you just use a dispatch queue or a timer to do the job.

    void MyTakeScreengrab();
    
    dispatch_queue_t  queue    = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,  0);
    
    dispatch_source_t timerSrc = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,0,0,queue);
    
    dispatch_source_set_timer(timerSrc, 
          dispatch_time(DISPATCH_TIME_NOW,0) /* start on */,
          SECONDS_PER_GRAB * NSEC_PER_SEC /* interval */, 
          NSEC_PER_SEC /* leeway */);
    
    dispatch_source_set_event_handler_f(timerSrc, MyTakeScreengrab);
    
    dispatch_resume(timerSrc);
    

    You can use an NSTimer as well.

    -(void)setup {
        _timer = [[NSTimer scheduledTimerWithTimeInterval: (NSTimerInterval)SECONDS_PER_GRAB 
                target: self 
                selector: @selector(takeScreegrabOnBGThread:) 
                userInfo: @{ @"folderPath" : MyFolderPath(), 
                             @"imageSettings" : MYCGImageSettings() }  
                repeats: YES];
        [_timer fire];
    }
    
    -(void)takeScreengrabOnBGThread:(id)userInfo {
        [self performSelectorInBackground:@selector(takeScreengrabBlocking:) 
                withObject:userInfo];
    }
    
    -(void)takeScreengrabBlocking:(id)userInfo {
    
        MyTakeScreengab(userInfo);
    }
    

    To use the terminal to do this, the command you’re looking for is screencapture(1).

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

Sidebar

Related Questions

I have a problem that I have been trying to figure out for hours
I have been trying to figure out how eBay would create their forms in
I have been trying to figure out how to create a treeview which is
I have been trying to figure out a way to make wget only create
I have been trying to figure this out for a bit. I create a
I have been trying to figure out why I am getting this problem and
I have been trying to figure out how to read paragraph content which exists
I have been trying to figure out how to open a file from the
I have been trying to figure out a solution but nothing has really presented
I have been trying to figure out a way to tag several methods from

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.