macOS screenshots
The screenshot tool that comes with your Mac, a small script and a keyboard shortcut. Nothing to install.
The script uses screencapture to select an area, curl to upload, pbcopy for the link and plutil to read the answer. All of them come with macOS.
1. Make an uploader on your server
- Sign in to your server and open Settings > Uploaders, then Add uploader.
- Pick macOS screenshots, give it a name you'll recognize, and check the folder, visibility and link style. The defaults are fine.
- The next page has these same steps with your server and token already filled in. The token is shown once, so copy it or download the files now.
The snippets below use https://drive.example.com and stu_YOUR_UPLOADER_TOKEN. Swap in your own if you set things up by hand.
2. Install the script
- Download
stavo-screenshot.shfrom the uploader's page (or save the script below), then in Terminal:mkdir -p ~/bin mv ~/Downloads/stavo-screenshot.sh ~/bin/ chmod +x ~/bin/stavo-screenshot.sh - Try it. Select an area; the link is on your clipboard.
~/bin/stavo-screenshot.sh - The first run asks for Screen Recording permission for Terminal or Shortcuts. Allow it in System Settings > Privacy & Security.
3. Give it a key with Shortcuts
- Open Shortcuts, make a new shortcut and add Run Shell Script with this line:
~/bin/stavo-screenshot.sh - In the shortcut's details choose Add Keyboard Shortcut and press the keys you want.
Upload files from Finder
- Make another shortcut, turn on Use as Quick Action for Finder, and have it receive Files.
- Add Run Shell Script, set Pass Input to as arguments, and use:
~/bin/stavo-screenshot.sh "$@" - Right click any file, Quick Actions, and the link is on your clipboard.
The script
#!/bin/bash
# Select an area (Space switches to a window, Esc cancels), it uploads and copies the link.
# Pass file paths to upload those instead (Shortcuts and Quick Actions do that).
set -euo pipefail
SERVER="https://drive.example.com"
TOKEN="stu_YOUR_UPLOADER_TOKEN"
notify() { osascript -e "display notification \"$2\" with title \"$1\"" >/dev/null 2>&1 || true; }
upload() {
local resp url
resp="$(curl -sS -H "Authorization: Bearer $TOKEN" -F "file=@$1" "$SERVER/api/v1/upload")" || { notify "Upload failed" "Couldn't reach the server"; exit 1; }
url="$(printf '%s' "$resp" | plutil -extract url raw -o - - 2>/dev/null || true)"
if [ -z "$url" ]; then
notify "Upload failed" "$(printf '%s' "$resp" | plutil -extract error raw -o - - 2>/dev/null || echo "No answer from the server")"
exit 1
fi
printf '%s' "$url" | pbcopy
notify "Link copied" "$url"
echo "$url"
}
if [ "$#" -gt 0 ]; then
for f in "$@"; do upload "$f"; done
exit 0
fi
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
shot="$tmp/Screenshot $(date '+%Y-%m-%d at %H.%M.%S').png"
screencapture -i -x "$shot"
[ -s "$shot" ] || exit 0
upload "$shot"