Skip to content

Instantly share code, notes, and snippets.

@andytlr
Last active August 29, 2015 14:01
Show Gist options
  • Save andytlr/7f9fa80c2c20b8a2de12 to your computer and use it in GitHub Desktop.
Save andytlr/7f9fa80c2c20b8a2de12 to your computer and use it in GitHub Desktop.
Better OS X Screenshots
# This will capture a screenshot, put it in your Public Dropbox folder,
# reveal it in Finder and copy a sharable URL to the clipboard. E.g.
# https://dl.dropboxusercontent.com/u/21267/shots/shot_2014-05-19_12-30-48.png
# Uncomment options below for things like opening in Preview,
# copying a Markdown/HTML image tag etc.
# Replace with your Dropbox user ID.
#
# Share something from your Public folder to find it.
# It's the number following /u/ in the URL.
dropboxuser=21267
# The folder inside your public folder you want screenshots to go to.
foldername=shots
# The filename for each screenshot. Includes date and time to maintain order.
filename=shot_`date '+%Y-%m-%d_%H-%M-%S'`.png
# Makes the containing directory if it doesn't exist.
path=~/Dropbox/Public/$foldername/
mkdir -p $path
# Takes the screenshot
#
# The `-i` sets interactive mode so you can select a region.
# Hit space to change to window selection mode.
#
# The `-o` removes the window shadow from window selections.
# If you dig that, remove it.
#
# Change `-o -i` to `-m` for full screen screenshots instead,
# `-m` forces a multi-monitor setup to only capture the main monitor.
screencapture -o -i $path$filename
# Reveal in Finder
open --reveal $path$filename
# Open in Preview
# open -a 'Preview' $path$filename
# Build Dropbox public URL
#
# It will 404 until the file has finished uploading
publicurl=https://dl.dropboxusercontent.com/u/$dropboxuser/$foldername/$filename
# Copy URL to clipboard
printf $publicurl | pbcopy
# Copy Markdown image tag instead
# printf "![]($publicurl)" | pbcopy
# Copy HTML image tag instead
# printf "<img src="$publicurl" alt="" />" | pbcopy
# Open the URL in your default browser
# open $publicurl
@andytlr
Copy link
Author

andytlr commented May 19, 2014

Can be triggered with a hotkey by making an OS X System Service

  1. Open Automator.app
  2. Create a new 'Service'
  3. Change 'Service recieves selected text' to 'Service recieves no input'.
  4. Search for 'Run Shell Script' and add it.
  5. Paste this script in.
  6. Save it. It should go to ~/Library/Services.
  7. Go to System Preferences, then 'Keyboard'. Select 'Shortcuts' then 'Screen Shots' in the sidebar.
  8. Uncheck 'Save picture of selected area...' so you can re-use that shortcut.
  9. Select 'Services' from the sidebar and find the service you created. It should be at the bottom of the list under 'General'
  10. Add a shortcut. Use Cmd + Shift + 4 to replace the system version.

@andytlr
Copy link
Author

andytlr commented May 19, 2014

Various Related Commands

Convert the URL on clipboard to a Markdown image tag

I use Ctrl + Opt + Cmd + i.

printf "![](`pbpaste`)" | pbcopy

May need to escape the ! by putting a \ before it.

Open output folder

I use Cmd + Shift + 2.

open ~/Dropbox/Public/shots/

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