‹ gerlach.coffee

A Dropbox Public Folder Replacement

At the beginning of the month, Dropbox deprecated their public folders. In case you didn’t know, public folders allowed you to put things into the public folder of your Dropbox, and then you could right-click on it, select copy public link and you’d be able to share whatever you put there right away. It was super convenient, but I assume too many people used it to host their website, and now Dropbox only provides links to the Dropbox website, that let you view or download the content.

I wanted to recreate this functionality, and thankfully AWS together with a few hacked together shell script and MacOS lovely scripting ability makes this very easy.

1) Create an S3 bucket and set up the AWS CLI tools

Just what it says on the tin. Don’t give it public read permissions. Make sure you’ve set up the AWS commandline tools (brew install awscli and then aws configure).

2) Create a synchronization script

Determine which folder you want to synchronize (for convenience' sake I chose ~/Dropbox/Public), and create a shell script to synchronize this folder to your newly created bucket. My script is:

#!/bin/sh
set -x #echo on

PUBLIC_FOLDER=$HOME/Dropbox/Public
PUBLIC_BUCKET="s3://max.public"

if ! [ -x "$(command -v aws)" ]; then
  echo 'Error: aws is not installed.' >&2
  exit 1
fi

aws s3 sync $PUBLIC_FOLDER $PUBLIC_BUCKET --acl public-read

Make the script executable and make sure that everything works as expected

3) Create a Folder Action to invoke the script

Open the MacOS Automator and create a new folder action. Choose your public folder and execute the synchronization script when any new files get added:

synchronize_public_folder

This is not quite as nice as Dropbox, because it only executes when files get added, not when they get changed, but you can always run the synchronization script yourself.

Create a new Automator file and this time select Service. Set up the service like so:

For ease of use, here is the script, ready to copy & paste:

for var in "$@"
do
    echo "$var" | sed "s_$HOME/Dropbox/Public_https://s3.amazonaws.com/YOURBUCKET_"
done

Now you’ll be able to copy the public link by simply right-clicking on a file and selecting Services -> Public Link (or whatever you chose to call your service):

5) You’re done

That’s it! Nice, eh?