Skip to content

Instantly share code, notes, and snippets.

@msabramo
Created January 1, 2011 01:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msabramo/761482 to your computer and use it in GitHub Desktop.
Save msabramo/761482 to your computer and use it in GitHub Desktop.
Create a service workflow in Automator with a "Run AppleScript" action with this for an easy shortcut for posting to pastebin.com (See http://marc-abramowitz.com/archives/2011/01/02/os-x-service-for-posting-text-to-pastebin-com/)
-- pastebin.workflow.applescript
--
-- An automator workflow to copy selected text to pastebin.com
--
-- Created by Marc Abramowitz
-- December 5, 2010
-- version 1.0
on run {input}
-- prep input for validation
set inputResult to (input as string)
-- Build the curl command to post to pastebin.com
set curlCMD to "curl --stderr /dev/null -d\"paste_code=" & urlencode(inputResult) & "\" http://pastebin.com/api_public.php"
-- Run the script and get the result:
set pastebinUrl to (do shell script curlCMD)
-- Open in default web browser
open location pastebinUrl
-- return result to be copied to the clipboard
return pastebinUrl
end run
on urlencode(theText)
set theTextEnc to ""
repeat with eachChar in characters of theText
set useChar to eachChar
set eachCharNum to ASCII number of eachChar
if eachCharNum = 32 then
set useChar to "+"
else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then
set firstDig to round (eachCharNum / 16) rounding down
set secondDig to eachCharNum mod 16
if firstDig > 9 then
set aNum to firstDig + 55
set firstDig to ASCII character aNum
end if
if secondDig > 9 then
set aNum to secondDig + 55
set secondDig to ASCII character aNum
end if
set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
set useChar to numHex
end if
set theTextEnc to theTextEnc & useChar as string
end repeat
return theTextEnc
end urlencode
@msabramo
Copy link
Author

msabramo commented Jan 4, 2011

@dattz
Copy link

dattz commented Apr 13, 2016

This is now obselete.
"THIS API HAS BEEN DISABLED. Please use Pastebin's new API. http://pastebin.com/api"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment