Skip to content

Instantly share code, notes, and snippets.

@ConorSheehan1
Last active December 5, 2020 00:06
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 ConorSheehan1/2a72b13fa530388dcaec93307f4f7b09 to your computer and use it in GitHub Desktop.
Save ConorSheehan1/2a72b13fa530388dcaec93307f4f7b09 to your computer and use it in GitHub Desktop.
on OSX / macOS manage screenshots from the terminal (list, copy, etc.)
# print the path to the latest screenshot
latest_screenshot() {
# get screenshot dir, replace ~ with $HOME (required for ls to work)
screenshot_dir=$(defaults read com.apple.screencapture location | sed "s;~;$HOME;")
# use ls -t to order by time, use head -n 1 to get only latest
file_name=$(/bin/ls -t $screenshot_dir | head -n 1)
# if REL is passed, show relative path (filename), otherwise show absolute path
if [[ -z "$REL" ]]; then
printf "%q\n" "$screenshot_dir/$file_name"
else
printf "%q\n" $file_name
fi
}
# copy the latest screenshot to the current directory
copy_latest_screenshot() {
# remove escape chars since we return path as string, and can't have mix. should be either quoted path, or escaped spaces.
screenshot="$(latest_screenshot | tr -d '\')"
echo "copying $screenshot"
cp "$screenshot" .
}
@ConorSheehan1
Copy link
Author

Python CLI implementation https://github.com/ConorSheehan1/shot
brew install conorsheehan1/conorsheehan1/shot

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