Automator service to create random dropbox link and email it

I use dropbox a lot to share files and a recurring task is to copy a file into the dropbox public folder, create a link and email it off. Additionally, I like using Merlin Mann’s trick of zipping a file, renaming it to something obscure and sending that link. Recently, I found Brian Hayes’s trick (via Macsparky) to streamline the process using Textexpander.

I wanted to adopt it to my workflow and created an automator service that I can run in the finder, with a file selected. It does the following:

You can save the service and access it in the finder by right-clicking on any file. I combine this with a Hazel rule that cleans out my public folder after a certain time. If you use this a lot you could set up a keyboard shortcut for the service in the keyboard preference pane.

Here is what the automator service looks like:

And here is the applescript:

on run {input, parameters}
set str to {}
set end of str to some item of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
repeat 12 times
set end of str to some item of "ABCDEFGHIJKLMNOPQRSTUVWXYZa;rndbcdefghijklmnopqrstuvwxyz1234567890`~!@#$%^&*()_+-=[]>?;:'"
end repeat
set randString to str as string
tell application "Finder"
set theFile to file input
set theNewName to (randString & ".zip")
set the name of file input to theNewName
(*Change the dropbox path if necessary*)
set dest_folder to folder "Documents:Dropbox:Public" of home
move file input to dest_folder
end tell
(*Change YOUR_DROPBOX_ID to your unique dropbox id*)
set the theURL to ("http://dl.dropbox.com/u/YOUR_DROPBOX_ID/" & my text2url(theNewName))
set the clipboard to theURL as text
tell application "Mail"
activate
make new outgoing message with properties {content:the clipboard, visible:true}
end tell
return input
end run
on text2url(thetext)
return do shell script "python -c \"import urllib, sys; print (urllib.quote(sys.argv[1]))\" " & quoted form of thetext
end text2url

Sebastian…
Are you pointing the script to the location of the Dropbox Public folder on your local hard drive? The one in this post assumes Dropbox is located at ~/Documents/Dropbox/Public. My Dropbox Public folder installed several years ago is at ~/Dropbox/Public. If you have my set up, you need to remove Documents: before the word “Dropbox” in the line that sets the path.

One other thought, the script wouldn’t work for me when I tried to point it to a subfolder I had created in my Dropbox Public folder. Don’t know why exactly unless the Dropbox ID one gets only works for the Public folder itself. So, again, make sure you are pointed squarely at your PUblic folder and see what happens.

I’ve reproduced your error. It only happens when you try to run the service from within automator, which you wouldn’t normally want to do. The service works as is. You activate it by right-clicking on any file in the finder -> services -> the name of the service.

When you run it from within Automator it doesn’t get an input file and both the archive and the applescript don’t work. If you ever want to test your services from within automator you need to add the action “get selected Finder items”, which will use the finder items you selected, or “get specified Finder items”, which uses a certain file whose path you specify.

This is quite elegant. You’ve built on a great idea hatched, I believe by Eddie Smith of Simplicity is Bliss fame, and enhanced by the guru Merlin Mann for emailing sensitive data. This Service works like a charm and when coupled with Merlin’s suggestion, picked up by you, of protecting things via a Hazel sweep rule, you’ve produced a no brainer way to send sensitive stuff via email as safely as possible. Thanks for this share!

This is a great script. I am new at scripting so can you pleas post a script that does all the above but that does NOT change the file name to a random string and rather keeps the name of the original file?
Thank you,
Alexis

I couldn’t find my Dropbox ID in a link of any sort which I tried to create from files & folders within my dropbox account – anyhow I just copied the entire link to my public folder and pasted that into your code replacing “http://dl.dropbox.com/u/YOUR_DROPBOX_ID/” – it even works when i right click a file in another folder – creates a zipped file and places that in the Public folder and you can share that.
Thanks