2016-08-18

In this post I’ll show you how to create an Automator service that uploads a selected file to Dropbox, generates a public Dropbox link and copies it to the clipboard. I’ll also show you how I automated this process for screen shots using Hazel.

Note: The technique I describe below does not rely on the deprecated Public folder that Dropbox disabled for accounts created after October 4th, 2012. Instead I use the Dropbox API to upload files and generate links.

The need for Automator

When I upgraded to the public beta of macOS 10.12 Sierra, I noticed that Annotate, my favorite screen capturing application wasn’t working. Using Annotate, I could grab screen shots and automatically upload them to Dropbox. Annotate would also generate a public Dropbox link that I could paste into an iMessage or an email.

Without Annotate, I was stuck using the screen capture mechanism that’s built into macOS. Shift + Command + 4 would allow me to select an area on my screen to capture and macOS would save the file in PNG format to my desktop. This approach had two disadvantages:

Location: I wanted my screen shots to be saved to Dropbox and not to my desktop

Link creation: Creating a public Dropbox link would require extra steps

I know you can tweak where macOS stores screen shots by default, but I was unsuccessful changing that in the public beta I’m using. But even if I could figure that out, I’d still have to navigate to the file in Finder and right-click on it to generate a Dropbox link.

How to generate a Dropbox link for any file

I realized that screen shots are not the only file types I wanted to be able to easily generate Dropbox links for. In fact, I wanted to be able to generate a Dropbox link for any file, no matter if it was stored in Dropbox or not. I’m in the process of moving much of my data from Dropbox to iCloud Drive and once that’s done, it won’t be as easy as right-clicking on a file in Finder anymore to generate a Dropbox link. So I decided to take a more generic approach by creating a system-wide service.

The service would do the following:

Take any file that’s selected in Finder and upload it to Dropbox

Once uploaded, generate a public Dropbox link

Copy the Dropbox link to the clipboard

Dropbox App

As a prerequisite you need to have a Dropbox account. If you don’t have one, sign up here and install the Dropbox app for macOS/OS X. Next you need to create a Dropbox app. To do that, follow these steps:

Log in to developer.dropbox.com

Click on My apps and then on Create app

Choose Dropbox API

Choose App folder as access type

Name your app – I called mine MKPublicShare

Choose your Dropbox account – if you have multiple

Generate your access token





The access token is a secret and is to be treated as such. So don’t lose it or share it with anybody! Once you have generate your access token, you will see a new folder in Dropbox/Apps/NameOfYourApp – for instance: ~/Dropbox/Apps/MKPublicShare. That’s the folder your newly created application will have access to.

Automator Service

Next fire up Automator using Spotlight or Launchpad and select Service as the document type. Make the following adjustment at the top of your service:

Service receives selected: files or folders in Finder

On the left-hand side, search for the following actions and drag them over, one by one, to the right side in the order as shown in the screenshot below:

Run Shell Script

Copy to Clipboard

Click into the text box under the Run Shell Script action and paste the following script. Make sure you change Pass Input to “as arguments“.

Replace “YOUR DROPBOX ACCESS TOKEN GOES HERE” with your actual Dropbox access token. Then save the service and give it a try.

Open Finder and select a file that’s smaller than 150mb (the limit of the API call I use)

Right-click the file, select Services and click on the name of your service

Depending on the size of the selected file, you should have a public Dropbox link in your clipboard a few seconds later

If you would like to get notified once the link was generated, simply add the Display Notification action at the end of your service. You can also create a keyboard shortcut for your service via System Preferences –> Keyboard –> Shortcuts –> Services. I use Control + Option + Command + D.

Processing Screen Shots with Hazel

For screen shots I didn’t want to have to right-click to generate a link. Instead I wanted to automate the process. Hazel is my go-to app for automating file handling processes. Hazel doesn’t support Automator services but it supports Automator workflows. So I created a new workflow that looks almost identical to my Automator service. The only difference is, we need an extra action on top called Get Selected Finder Items. So go ahead and create a new Automator document, choose type Workflow and add the following actions:

Get Selected Finder Items

Run Shell Script (paste the code from before and change Pass Input)

Copy to Clipboard

Optional: Display Notification

Then save it and open Hazel:

Add Desktop to your monitored Hazel folders (if not already there)

Create a new rule as shown in the screen shot

The rule looks for image files that have the words “Screen Shot” in the file name. If it finds one it renames the file and runs the Automator workflow on it. Then, it deletes the original file from the desktop.

Frequently Asked Questions

Q: Why not leverage the Public Dropbox folder instead of the API?

A: Dropbox deprecated the Public folder for accounts created after October 4th, 2012. So not everyone has that folder. If you still do, there are plenty of how-tos out there that show you how you can use it to generate public Dropbox links. The issue with the Public folder is that it reveals your Dropbox ID and the links can be guessed if you know the name of the shared file. Using the API, each link has a random component to it and cannot easily be guessed.

Q: Can you change the link sharing settings, such as expiration date and visibility?

A: You absolutely can by changing the curl statement from:

To something like:

That adds an expiration date of 3 weeks into the future and makes the link password protected using “Secret” as the password. Note that only Pro and Business accounts can use those features, Basic accounts cannot.

I hope you enjoyed this trick!

The post How to: Using Automator to Generate Dropbox Link appeared first on Michael Kummer.

Show more