Created
August 24, 2009 22:39
-
-
Save CasperTDK/174275 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# Dropzone Destination Info | |
# Name: Pastebin | |
# Description: Copies text from clipboard to pastebin.com. 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, format)) | |
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, format)) | |
end | |
def readClipboard | |
IO.popen('pbpaste') {|clipboard| clipboard.read} | |
end | |
def getPastebinUrl(data, format) | |
require 'net/http' | |
Net::HTTP.post_form(URI.parse("http://pastebin.com/pastebin.php"), | |
{"parent_pid" => "", | |
"format" => format, | |
"code2" => data, | |
"poster" => "", | |
"paste" => "Send", | |
"expiry" => "m", | |
"email" => ""}).header['Location'] | |
end | |
def getFormat | |
output = `./CocoaDialog dropdown --text "Which Format?" --items "Text" "Bash" "C" "C++" "HTML" "Java" "Javascript" "Lua" "Perl" "PHP" "Python" "Ruby" "None" "ABAP" "ActionScript" "Ada" "Apache Log File" "AppleScript" "ASM (NASM based)" "ASP" "AutoIt" "Bash" "Blitz Basic" "BNF" "C" "C for Macs" "CAD DCL" "CAD Lisp" "C++" "C#" "ColdFusion" "CSS" "D" "Delphi" "Diff" "DOS" "Eiffel" "Erlang" "Fortran" "FreeBasic" "Genero" "Game Maker" "Groovy" "Haskell" "HTML" "IDL" "INI" "Inno Script" "Java" "Javascript" "Latex" "Lisp" "Lua" "Linden Scripting Language" "MatLab" "M68000 Assembler" "MPASM" "mIRC" "MySQL" "NullSoft Installer" "Objective C" "OCaml" "Openoffice.org BASIC" "Oracle 8" "Pascal" "Perl" "PHP" "PL/SQL" "Python" "QBasic/QuickBASIC" "Rails" "Robots" "Ruby" "Scheme" "Smalltalk" "Smarty" "SQL" "TCL" "unrealScript" "VisualBasic" "VB.NET" "VisualFoxPro" "XML" "Z80 Assembler" --button1 "Ok" ‑‑no‑cancel --float` | |
return output.split("\n")[1] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment