forked from a4agarwal/dropzone-user-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpen URLS.dropzone
55 lines (50 loc) · 1.32 KB
/
Open URLS.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
#!/usr/bin/ruby
# Dropzone Destination Info
# Name: Open URLs
# Description: Parses dropped files, dragged text or the clipboard (on click) for http(s) links, opens them in Safari (or defined browser)
# Handles: NSFilenamesPboardType
# Creator: Brett Terpstra
# URL: http://brettterpstra.com
# IconURL: http://brettterpstra.com/destinations/icons/openurls.png
# Events: Clicked, Dragged
def clicked(was_dragged = false)
$dz.begin("Parsing text for links")
$dz.determinate(true)
if was_dragged == false
input = %x{__CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbpaste}.strip
else
input = was_dragged
end
links = input.scan(/((https?:\/\/)([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w&\?=.-]*)*\/?)/im)
if links.empty? then
$dz.finish("No links found")
$dz.url(false)
else
percent = 10
$dz.percent(percent)
norepeat = []
output = []
inc = 90 / links.length
links.each {|url|
unless norepeat.include?(url[0])
norepeat.push url[0]
%x{open "#{url[0]}"}
end
percent += inc
$dz.percent(percent)
}
$dz.finish("#{norepeat.length} links opened")
$dz.url(false)
end
end
def dragged
contents = ''
$items.each { |f|
if File.file?(f)
contents += File.new(f,'r').read + " "
else
contents += f + ' '
end
}
clicked(contents)
end