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.
-
Does anyone know how to do it?
-
Are there other possible ways besides CGImageRef to solve this problem? Could it for example be done via command-line tools and NSTask?
-
If so, what are the advantages/disadvantages with the different methods in terms of speed and complexity?
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.
You can use an NSTimer as well.
To use the terminal to do this, the command you’re looking for is
screencapture(1).