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:

  1. zip the file
  2. rename the zip to something obscure, using Brian’s code
  3. move the zip to the dropbox public folder
  4. create a link to that file, using this code from Chez Moncef, the dropbox forum and stackoverflow
  5. create a new email in mail.app and put the link into the body

To use this service for your needs, you need to edit two values:

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
Advertisements

22 thoughts on “Automator service to create random dropbox link and email it

  1. 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!

  2. Pingback: Share a bunch of files quickly and securely with Dropbox using Keyboard Maestro | Kaush's Journal

  3. 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

  4. 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s