Skip to content

Instantly share code, notes, and snippets.

@bhpayne
Created June 18, 2022 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhpayne/590e88acef89229540fdffaf6682da73 to your computer and use it in GitHub Desktop.
Save bhpayne/590e88acef89229540fdffaf6682da73 to your computer and use it in GitHub Desktop.
screenshots in mac osx with timer

For the impatient:

  1. determine the relative coordinates for the cropped screenshot
  2. determine the coordinates of the mouse click
  3. compile click.m using cc
  4. run the shell script
// File:
// click.m
//
// Compile with:
// gcc -o click click.m -framework ApplicationServices -framework Foundation
//
// Usage:
// ./click -x pixels -y pixels
// At the given coordinates it will click and release.
//
// From http://hints.macworld.com/article.php?story=2008051406323031
// and
// https://stackoverflow.com/a/26687223/1164295
#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
int x = [args integerForKey:@"x"];
int y = [args integerForKey:@"y"];
CGPoint pt;
pt.x = x;
pt.y = y;
CGPostMouseEvent( pt, 1, 1, 1 );
CGPostMouseEvent( pt, 1, 1, 0 );
[pool release];
return 0;
}
#!/usr/bin/env bash
# move the mouse to the relevant window and location
./click -x 1212 -y 777
# how many screenshots to take
for index in `seq -w 1 270`; do
echo slide $index
sleep 4
screencapture -x -R150,120,1130,700 slide_${index}.png
./click -x 1212 -y 777
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment