Robo

Dropbox in Snow Leopard (part deux)

Posted in Applescripts by Robin Ramael on August 30, 2009

You can do a lot of neat little things with the new automator services-template. In my last post I wrote about making a litle automation to replace a feature that wasn’t in dropbox in Snow Leopard, but you can go further. Why not make the service copy any selected file over to the dropbox public folder and then copy the public URL to the clipboard.

It’s basically the same automation as in part one, but the applescript does more:

(UPDATED)

1. Open up automator again and choose the services template.

2. At “Service receives selected” choose “all files and folders” in “all programs” (you can choose the finder too, but i don’t see why “all programs” would be an issue).

3. The workflow goes: –> execute applescript –> copy to clipboard

4. In the applescript section you write:

<(*Created by Robin Ramael on 29th of august 2009
Under Creative Commons License Attribution-NonCommercial (http://creativecommons.org/licenses/by-nc/3.0/)

FILL IN YOUR DROPBOX USER ID BELOW!!!!
*)

on run {input, parameters}
 
 (*FILL IN YOUR DROPBOX USER ID HERE*)
 set userid to 244025
(*FILL IN MAXIMUM FILESIZE  (in mb) HERE*)
 set maximumfilesize to 50


  
 set dropboxpath to (path to home folder) & "Dropbox:Public:" as string
 
 (*Check if filesize isn't too big*)
 get size of (info for input)
 set filesize to result / 1000000
if filesize is greater than maximumfilesize then
 say "woaw"
 display dialog "This file is larger than 50 mb, are you sure you want to upload it to Dropbox?" with icon caution
 end if
 
 (*Copy file*)
 tell application "Finder"
 duplicate input to folder dropboxpath with replacing
 end tell
 
 (*Get the name of the file to put in clipboard later in the automation*)
 tell application "Finder"
 get name of (info for input)
 set filename to result
 set dURL to "http://dl.getdropbox.com/u/" & userid & "/" & filename as string
 end tell
 
return dURL
end run

(Replace the ‘xxxxxx’by your dropbox user id. Remember, you can get this ID by going to any of your public files in the browser and looking at the URL. For example, if you have the URL “http://dl.getdropbox.com/u/123456/file.txt”, 123456 is your user ID.

You also might have to replace the “smart quotes” with normal quotes, i’d put in


tags but there is no support for them with applescript…)

5. Save as “Copy to Public Dropbox and copy URL”  and we’re done! You can now go to any file , right-click it and click  ”Copy to Public Dropbox and copy URL” or whatever you named it and voila, the file is copied to your dropbox and the URL is copied to your clipboard.

The applescript also checks if the filesize isn’t too big (default is larger than 50 mb, but you can change that) to make sure you don’t accidentally start uploading a 4 GB file to you tiny, tiny dropbox.

UPDATE:  This currently only works with some filenames. Filenames with spaces or presumably backslasher are ‘not yet supported.’I’ll have to poke myself for version 1.01.

Advertisement

5 Responses

Subscribe to comments with RSS.

  1. [...] October 9, 2009 A few weeks ago I posted an applescript that could be used in an automator-service to automativally upload a file to your public dropbox and copy the URL to your clipboard. You can find that post here) [...]

  2. monototo said, on November 2, 2009 at 10:08 am

    Thanks for this, it’s really good. However, I ran into a couple of snags getting it to work.

    First up, when you’ve copied the code into wordpress it’s changed all of your quotes into “smart quotes”. So before the script will run people will have to do a find + replace (watch out for the single quote marks following the sed command, they need changing as well.

    Also, your comments were originally proceeded by two hyphens but wordpress has changed them as well.

    Could I suggest that before you copy code into wordpress you try something like

    (and then finish up with a 

    .

    Finally, the original automation instructions are missing the final instruction, to include the “copy to clipboard” Action onto the end of the workflow. Anyway, thanks for the script, it was just what I was looking for.

    Cheers

  3. monototo said, on November 2, 2009 at 10:11 am

    bah, i wasn’t expecting wordpress to format my code :D

    I’m talking about the square bracket sourcecode language = html thing mentioned here
    http://en.support.wordpress.com/code/
    under “posting sourcecode”

    ciao

    • Robin Ramael said, on November 2, 2009 at 1:25 pm

      Thanks, i hadn’t noticed. unfortunately there’s no support for applescript so i changed the comment-syntax and warned for the smart quotes. Is there some kind of raw text tag? I couldn’t find anything ot that…


Leave a Reply

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

Gravatar
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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.