Last active
December 5, 2020 00:06
-
-
Save ConorSheehan1/2a72b13fa530388dcaec93307f4f7b09 to your computer and use it in GitHub Desktop.
on OSX / macOS manage screenshots from the terminal (list, copy, etc.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" . | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python CLI implementation https://github.com/ConorSheehan1/shot
brew install conorsheehan1/conorsheehan1/shot