forked from a4agarwal/dropzone-user-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dropbox.dropzone
61 lines (54 loc) · 1.63 KB
/
Dropbox.dropzone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/ruby
# Dropzone Destination Info
# Name: Dropbox
# Description: Share files via Dropbox by copying them to your Dropbox Public folder and putting the URL on the clipboard.
# Handles: NSFilenamesPboardType
# Creator: Philipp Fehre
# URL: http://sideshowcoder.com
# IconURL: http://aptonic.com/destinations/icons/dropbox.png
# Events: Dragged, Clicked
# OptionsNIB: DropboxLogin
require 'base64'
require 'set'
@dropboxPubDir = ""
@dropboxPublicBaseURL = "http://dl.getdropbox.com/u/"
def check_for_dropbox
# Get Dropbox Public directory
begin
File.foreach(ENV['HOME'] + "/.dropbox/host.db") { |line| @dropboxPubDir = Base64.decode64(line) + "/Public/" }
return true
rescue Errno::ENOENT
# Dropbox is not installed on this machine
return false
end
end
def dragged
$dz.determinate(true)
# Check and set Public path
if not check_for_dropbox
$dz.finish("Dropbox is not installed")
$dz.url(false)
else
# Check and set file path
path = $items[0]
if File.directory?(path)
$dz.finish("Only files please")
$dz.url(false)
else
# Copy file to Public folder and set URL
$dz.begin("Copying #{File.basename(path)} ...")
Rsync.do_copy(path, @dropboxPubDir, false)
$dz.finish("URL is now on clipboard")
$dz.url(@dropboxPublicBaseURL + ENV['USERNAME'] + "/" + File.basename(path))
end
end
end
def clicked
if not check_for_dropbox
$dz.determinate(false)
$dz.finish("Dropbox is not installed")
$dz.url(false)
else
`osascript -e 'tell application "Finder"' -e 'activate' -e 'open folder POSIX file "#{@dropboxPubDir}"' -e 'end tell'`
end
end