Dropbox Service
Author: Oliver S (kamikaze28)
Contents |
Description
Requires Mac OS X 10.5 (Leopard) +
These services will appear in every contextual menu of files. You are now just 2 clicks away from posting something to Dropbox!
Installation
Drag 'Move to Dropbox.workflow' and/or 'Copy to Dropbox.workflow' to
- 10.6 Snow Leopard: `~/Library/Services/`
- 10.5 Leopard: `~/Library/Workflows/Applications/Finder/` (create these folders if necessary)
Open the workflows in Automator and edit the Python script (in the block 'run shell-script) Change value of dropboxID = '<DROPBOX-ID>' To your ID. For example, look at the download link at the bottom of this page - you can see my Dropbox-ID there:
http://dl.dropbox.com/u/'''7925'''/Post%20to%20Dropbox.zip
Note: The script is designed to work with your Dropbox in the default location. If your Dropbox resides in a different place, consult the attached readme for instructions on how to change the script to work properly.
Usage
Right-click on a file or folder (in Finder, Mail, ...) and select 'Move/Copy to Dropbox' from the contextual menu. (Note: On 10.5 Leopard the new actions will be underneath `More › Automator` in the contextual menu.) Files will be put into your Dropbox public folder, auto-synched and the URLs to these files will be put in to the clipboard. In the case of folders, the URLs of all the files within the folders will be copied to clipboard. Files of the same name will not be replaced. If you want to change this, you can edit the 'Move/Copy Finder items'-block in the workflow (there is a checkmark to enable 'overwrite existing files').
Source Code
Here is the Python script, that converts files and folders into the public links:
import os, sys, urllib
# Enter your Dropbox ID here. If a public link form you looks like
# http://dl.getdropbox.com/u/7925/Post%20to%20Dropbox.zip
# your Dropbox-ID is 7925 and this line has too look like this:
# dropbox_id = '7925'
dropbox_id = '<DROPBOX-ID>'
copied_files = []
for arg in sys.argv[1:]: #for all input arguments
if os.path.isdir(arg): # if it is a directory
for root, dirs, files in os.walk(arg) : #traverse it
for file in files: #and for every file
if not file.startswith("."): #if it isn't a hidden file
current_file = os.path.join(root, file) # compose the path
copied_files.append(current_file) # and add it to our list
if os.path.isfile(arg): # if it is a file
if not arg.startswith("."): #if it isn't a hidden file
copied_files.append(arg) # just append it to the list
pasteURLs = [];
for file in copied_files: # for all elements in our list
components = file.split(os.sep) # seperate the path
local_dir = os.path.join(components[5:]) # cut off the beginning
local_dir = urllib.quote(local_dir) # convert it to a URL (' ' -> '%20', etc.)
#construct the URL
finalURL = 'http://dl.dropbox.com/u/%s/%s' % ( dropbox_id, local_dir )
pasteURLs.append(finalURL) # add the current URL to the string
copy_string = "\n".join(pasteURLs)
os.system( "echo '%s' | pbcopy" % (copy_string) ) # put the string into clipboard
Links
Download dl.dropbox.com/u/7925/Post%20to%20Dropbox.zip
Optional
To have the links in your clipboard force a download, add '?dl' to this line in the python scripts:
finalURL = 'http://dl.dropbox.com/u/%s/%s' % ( dropbox_id, local_dir )
would become:
finalURL = 'http://dl.dropbox.com/u/%s/%s?dl' % ( dropbox_id, local_dir )