Skip to content

Instantly share code, notes, and snippets.

@allancalix
Created August 22, 2021 00:27
Show Gist options
  • Save allancalix/a021a717a3d19fef251b958eb9643c33 to your computer and use it in GitHub Desktop.
Save allancalix/a021a717a3d19fef251b958eb9643c33 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# By default, Mac saves screenshots to the user's desktop. This simple script
# sets the directory screenshots are saved to turns off the screenshot
# confirmation popup. This script only works on MacOS.
#
# Example:
# ./set-screenshot-dir.sh $HOME/Screenshots
set -e
TARGET="$1"
if [[ -z "$TARGET" ]]; then
echo "Must provide desired screenshot output directory."
exit 0
fi
if [[ ! -d "$TARGET" ]]; then
echo "Creating output directory ${TARGET}"
mkdir -p "$TARGET"
fi
# Overrides location to store screenshot from desktop to provided directory.
defaults write com.apple.screencapture location "$TARGET"
# Skips the screenshot preview popup step.
defaults write com.apple.screencapture show-thumbnail -bool FALSE
# Restart UI server to take effect immediately.
killall SystemUIServer
@allancalix
Copy link
Author

Can run directly from gist using:

curl https://gist.githubusercontent.com/allancalix/a021a717a3d19fef251b958eb9643c33/raw | bash -s $HOME/Desktop/Screenshots

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment