Mac O’Clock
Published in

Mac O’Clock

How to automatically add a shadow to your screenshots on macOS

Photo by Josh Carter on Unsplash

OK, I know, this might sound quite a peculiar topic at first but maybe you can get some interesting tips from the whole story.

So I work with Confluence and since Atlassian is continuously improving their product removing useful features, we need to adapt and find workarounds; one feature that I am missing the most is the ability to drop a shadow behind an image that you can put on a Confluence page. This was particularly useful, ça va sans dire, to increase the contrast in case your image had a white background.

I write a lot of Guides and How-To for our internal products and procedures, which means that most, if not all the images I use in Confluence are screenshots (I use macOS, so Shift+Cmd+4 is my best friend).

So the problem I wanted to solve was: “In macOS, how can I automatically add a shadow to a screenshot image right after having taken it?”.

Note: This is all bash scripting and command line interface magic, so if you aren’t comfortable with the terminal this guide is not for you, sorry.

  1. First of all you need ImageMagick installed (it should be just a brew update && brew install imagemagick away, if you haven’t it already; try executing convert to check)
  2. Then you need a script which takes an image and updates it, creating another file with the added shadow. I made mine a bit fancy, so I prefer if you can take it from this gist instead of just copying it here in full (you have to customize it a bit since I left my directory names in there).
    Warning! Keep in mind that I changed my default screenshot directory to ~/Screenshots (not necessary for this task, but it’s better to not have a script running on what you put on your Desktop — default place for screenshots!)
  3. Now you need to tell your system that once you take a screenshot, you have to run the script you created in (2). You have to write a “plist” file and put it in your ~/Library/LaunchAgents directory. You can find the one I use in this other gist. I named it user.screenshot.drop_shadow.plist
  4. Finally you have to activate the “plist” file using the launchctl command: launchctl load path/to/your/file.plist

And now, when I take a screenshot after around 5 seconds I got also a version with an added shadow.

Some additional tips

  • The script you write is ran without a $PATH set, so you must use full path name of any installed binary you want to use
  • The script is technically ran when the directory specified in the .plist file changes, so also when a new file is added to it (using WatchPaths). The problem is that the script doesn’t receive any additional information, so you need to find what changed by yourself: I simply use the newest file in the directory with a name that starts with “Screenshot”
  • If you want to stop the .plist to monitor your directory, don’t forget to unload it using the launchctl command, the same way you loaded it
  • The bash script I linked can also be used as a simple way to add a shadow to any image you want, and can be run manually as you wish

Thanks for reading, maybe I can interest you in my Twitter and Instagram feed?

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store