Dropbox Applescript
A couple of people asked me for an AppleScript that would copy a given file to their Public Dropbox folder, and then copy the public URL to the clipboard. In this post I’ll give you the script, talk you through it, and how to customise it to use it yourself.
on splitText(delimiter, someText)
set prevTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to delimiter
set output to text items of someText
set AppleScript's text item delimiters to prevTIDs
return output
end splitText
on open {dropped_item}
set myPath to (path to home folder) as string
set myPath to myPath & "Dropbox:Public:"
tell application "Finder" to duplicate (dropped_item) to folder (myPath as string)
set fileName to item (count splitText(":", dropped_item as text)) of splitText(":", dropped_item as text)
set filePath to "https://dl.getdropbox.com/u/1083712/" & fileName
tell application "Finder" to set the clipboard to filePath as text
end open
The first chunk of code, starting with “on splitText” and ending with “end splitText” is just an function required to split a string apart at a given delimiter. This may already be built into AppleScript; if so, I couldn’t find it, so I’ve got a custom function to do it for me.
The next lines of the code say what to do when a file is dropped onto the Application. It gets your home directory, and appends “Dropbox:Public:” onto it – this assumes that your Dropbox is installed in the standard location. If not, you’ll have to set the variable “myPath” to wherever your Dropbox is actually located, using the syntax “Path:to:dropbox:folder:”.
Next, the AppleScript copies the file to that folder, and then uses the splitText function to get the individual file name. This is then added to the end of your public Dropbox URL (you will have to change this to your own URL – the current one is mine). The resulting URL is then inserted into the clipboard, ready for you to paste somewhere useful.
To use this script, alter the lines above that need changing, then use the File > Save As menu to save this as an Application. Now, whenever you drop a file onto it, it will get copied to your Dropbox Public folder, and the public URL copied into the clipboard.
You can download the Application (along with a custom icon) here. Open this with Script Editor and edit as above.
Enjoy!
Marc Amos
7 comments
Kyle October 14, 2009 at 9:30 pm
Thanks for the script – it works as advertised… unless you filename has spaces in it. I’m going to take a crack at modifying your code to see if i can get it to work regardless, but i thought i’ld give you a heads up.
thanks!e
Resources Roundup: 25 Links to the Best AppleScripts Tutorials and Examples October 19, 2009 at 5:32 pm
[...] Dropbox Applescript [...]
elasticthreads October 19, 2009 at 9:24 pm
Thanks. I implemented the script as a snow leopard service so you can just right click on a file and run the script. Also added that, if you’re trying to run it on a file that’s already in your dropbox/public, it won’t re-copy the file there but still give you the public URL
http://tr.im/Cl5d
gemmes October 20, 2009 at 8:39 pm
How would I or could you possibly create a .scpt file to go with it so I just select a file and hit a keyboard shortcut to send the file to the .app file.
Dont really know AppleScript, maybe a dumb question but this would be more useful to me.
How To: Save Time with Dropbox and AppleScripts Launchers October 20, 2009 at 9:21 pm
[...] an incredible time saving hack, totally worth messing a little bit with AppleScripts. (thanks to Ben Cardy for the [...]
gemmes October 20, 2009 at 9:49 pm
I created a small .scpt file to trigger a FastScripts keyboard shortcut:
tell application “Finder” to open the selection using “Macintosh HD:Users:Jono:Documents:File A.app”
gemmes October 20, 2009 at 9:51 pm
Oops, pasted code from google search. Should be something like this:
“Macintosh HD:Users:username:Documents:SendtoDropbox.app”