I often want to share screenshots in text chat from my computer, and I don't like sharing Dropbox links since they load a huge HTML+JS app just to show an image.
Since I already have a Micropub Media Endpoint that apps like Quill use to upload photos, I thought that would be a good place to also share screenshots from. The Media Endpoint is a simple HTTP API. It accepts a file upload, and returns the URL to the file in the Location header.
OSX has what's called "Folder Actions" where the system will trigger a script to run any time a file is added to a folder. I created an Automator script that will upload the newly added file to the media endpoint, and copy the resulting URL onto the clipboard.
The curl command I used is below. Of course you'll want to change the values of the access token and endpoint URL for yourself:
curl -i -F "file=@$1" -H "Authorization: Bearer xxx" https://media.aaronpk.com/endpoint.php | grep Location: | sed -En 's/^Location: (.+)/\1/p' | tr -d '\r\n' | pbcopy
To activate the Folder Action, save this in:
Now, open Finder to the folder where your screenshots are saved, and right click the folder and navigate to "Folder Actions Setup".
Attach the script to the folder in the window that appears. Your script should appear in the list once you've saved it to your "Folder Actions" folder in ~/Library.
Now, whenever you take a screenshot (or drop any other file in that folder), the Automator workflow will run and will upload your image to your media endpoint! After a few seconds, you should see a popup notification that the URL to your file is on your clipboard.