Skip to content

Instantly share code, notes, and snippets.

@scmx
Last active May 9, 2018 06:09
Show Gist options
  • Save scmx/b9b5cd6e35c838a51038a51c332d4896 to your computer and use it in GitHub Desktop.
Save scmx/b9b5cd6e35c838a51038a51c332d4896 to your computer and use it in GitHub Desktop.
Mac OS Screenshot with TouchBar #macos #screenshot #touchbar #imagemagick #convert #append #resize

Mac OS Screenshot with TouchBar

Many know that there are some keyboard bindings on Mac OS for taking screen shots

  • <Cmd> + <Shift> + 3 Full screenshot
  • <Cmd> + <Shift> + 4 Choose rectangle of what to screenshot
  • <Cmd> + <Shift> + 4 + <Space> Choose an app to screenshot

But for those with a Macbook Pro with a Touch Bar there is also

  • <Cmd> + <Shift> + 6 Screenshot of TouchBar

What if I wanted one image with both the screen and the touch bar, without having to open the images in an app?

screenshot touchbar-20180508-211011

First use the built in terminal screencapture command screencapture screenshot.png

The -b flag is used to take screenshot of touch bar instead screencapture -b touchbar.png

Then imagemagick to the rescue! brew install imagemagick.

Resize the touchbar image to same width as the screenshot convert touchbar.png -resize 2880 touchbar.png

Append the images convert screenshot.png touchbar.png -append screenshot-with-touchbar.png

#!/usr/bin/env bash
set -e
default_dir="$HOME/Desktop"
default_name="screenshot+touchbar-$(date +%Y%m%d-%H%M%S).png"
usage() {
cat <<USAGE
Usage: screenshot-with-touchbar [filename | path]
Takes a screenshot of your Screen and your TouchBar, combined into one image.
Arguments:
filename or a path Defaults to $default_dir/$default_name
Flags:
-o, --open Open image afterwards
USAGE
}
while [[ $# -gt 0 ]]; do
case "$1" in
"-o"|"--open")
open_afterwards=1
shift
;;
*)
if [[ -n "$desired_path" ]]; then
usage
exit 1
fi
desired_path="$1"
shift
;;
esac
done
desired_path=${desired_path:-$default_dir}
if [[ -d "$desired_path" ]]; then
desired_path="$desired_path/$default_name"
fi
dir=$(mktemp -d)
cd "$dir"
screencapture screen.png
screencapture -b touchbar.png
convert touchbar.png -resize 2880 touchbar.png
convert screen.png touchbar.png -append screenshot-with-touchbar.png
cp screenshot-with-touchbar.png "$desired_path"
if [[ "$open_afterwards" = "1" ]]; then
open screenshot-with-touchbar.png
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment