Paul Calnan
Published October 21, 2014

I regularly make QuickTime screen recordings of demos for clients. While it's easy to capture the entire screen, it's tricky when you want to capture only a single window. You need to open QuickTime Player, select New Screen Recording, then drag a rectangle over the exact area of the screen where the window is located. It's that last part that's a real pain. Even worse, if you have to do multiple takes, you need to drag out the selection rectangle each time.

One day, after around ten failed takes of a demo I was trying to do with a live voiceover, I got fed up and automated the process.

You can use AppleScript to get the target window's position and to kick off the screen recording. You need to change the process name (here, it's configured to record the iOS Simulator) and possibly the window number (if the app has more than one window).

I couldn't figure out a way to get AppleScript to move or drag the mouse. Originally, this required a small C program. I was recently able to replace it with a Swift script:

The script, saved in my ~/bin directory, takes four arguments: the starting x- and y-coordinates and the x and y distance to move the mouse. For example:

~/bin/clickdrag -x 10 -y 20 -dx 200 -dy 100

This moves the mouse to pixel (10, 20) on the screen, simulates a left mouse button press, waits a half second, drags the mouse 200 pixels to the right and 100 pixels down, waits another half second, and releases the mouse button.

It's not very polished, and you may need to tweak the delays here and there to make it work, but it's better than having to do it by hand.