Take screenshots/videos of macOS windows from the command line

? Support this work via GitHub Sponsors

macosrec

Take screenshots or videos of macOS windows from the command line.

Note: This gif was captured with macosrec

$ macosrec
USAGE: record-command [--list] [--screenshot <window number>] [--record <window number>] [--end]

OPTIONS:
  -l, --list              List recordable windows.
  -s, --screenshot <window number>
                          Take a screenshot of window number.
  -r, --record <window number>
                          Start recording window number.
  -e, --end               End recording.
  -h, --help              Show help information.

Screenshot

Before taking a screenshot, identify the window number using --list.

$ macosrec --list

21902 Emacs
22024 Dock - Desktop Picture - Stone.png
22035 Firefox - Planet Emacslife

Use --screenshot + window number to take a screenshot.

~ $ macosrec --screenshot 21902
~/Desktop/2023-04-14-08:21:45-Emacs.png

Videos (gif)

Before taking a video, identify the window number using --list.

$ macosrec --list

21902 Emacs
22024 Dock - Desktop Picture - Stone.png
22035 Firefox - Planet Emacslife

Use --record + window number to start recording a video (gif).

Note: you can also use application name and it will use the first window it finds belonging to it.

To end recording, send a SIGINT signal (Ctrl+C from terminal). Alternatively, running macosrec --end from another session would also end the recording.

~ $ macosrec --record 21902
Saving...
~/Desktop/2023-04-14-08:21:45-Emacs.gif

Note: you can also use application name and it will use the first window it finds belonging to it.

~ $ macosrec --record emacs
Saving...
~/Desktop/2023-04-14-08:21:45-Emacs.gif

Optimizing gif

The gifs can get pretty large fairly quickly depending on the lenght of the recording. Consider using something like gifsicle to reduce size. For example:

gifsicle -O3 large.gif --lossy=80 -o smaller.gif

Disclaimer

I built this util to record demos I post at xenodium.com. Does the job so far, but can likely take improvements, specially around image handling efficiency. PRs totally welcome.

? Support this work via GitHub Sponsors

GitHub

View Github