forked from a4agarwal/dropzone-user-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickPastebin.dropzone
55 lines (46 loc) · 2.12 KB
/
QuickPastebin.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: QuickPastebin
# Description: Copies text from clipboard to pastebin.com with out format. Replaces clipboard with pastebin url. Dragging text is possible as well.
# Handles: NSStringPboardType
# Events: Clicked, Dragged
# Creator: CasperT
# URL: portableinfo.com
# IconURL: http://portableinfo.com/pastebin.png
def dragged
$dz.begin("Sending text to pastebin...")
$dz.determinate(false)
data = $items[0]
#format = getFormat()
$dz.finish("Pastebin URL Copied!")
$dz.url(getPastebinUrl(data))
end
def clicked
$dz.begin("Sending text to pastebin...")
$dz.determinate(false)
data = readClipboard()
#format = getFormat()
$dz.finish("Pastebin URL Copied!")
$dz.url(getPastebinUrl(data))
end
def readClipboard
IO.popen('pbpaste') {|clipboard| clipboard.read}
end
def getPastebinUrl(data)
require 'net/http'
r = Net::HTTP.post_form(URI.parse("http://pastebin.com/api_public.php"),
{"paste_parent_key" => "",
"submit" => "submit",
"paste_subdomain" => "",
"paste_format" => "text",
"paste_code" => data,
"paste_name" => "",
"paste_private" => "0",
"paste_expire_date" => "N",
"paste_email" => ""})
r.body
end
def getFormat
result = `./CocoaDialog dropdown --text "Which Format?" --items "text" "bash" "c" "cpp" "html4strict" "java" "javascript" "lua" "perl" "php" "python" "ruby" "abap" "actionscript" "ada" "apache" "applescript" "asm" "asp" "autoit" "bash" "blitzbasic" "bnf" "c" "c_mac" "caddcl" "cadlisp" "cpp" "csharp" "cfm" "css" "d" "delphi" "diff" "dos" "eiffel" "erlang" "fortran" "freebasic" "genero" "gml" "groovy" "haskell" "html4strict" "idl" "ini" "inno" "java" "javascript" "latex" "lisp" "lua" "lsl2" "matlab" "m68k" "mpasm" "mirc" "mysql" "nsis" "objc" "ocaml" "oobas" "oracle8" "pascal" "perl" "php" "plswl" "python" "qbasic" "rails" "robots" "ruby" "scheme" "smalltalk" "smarty" "sql" "tcl" "unreal" "vb" "vbnet" "visualfoxpro" "xml" "z80" --button1 "Ok" ‑‑no‑cancel --float --string-output`
return result.split("\n")[1]
end