Skip to content

Instantly share code, notes, and snippets.

@tdlm
Last active January 11, 2018 00:47
Show Gist options
  • Save tdlm/5eba0299f2924a8aaf46 to your computer and use it in GitHub Desktop.
Save tdlm/5eba0299f2924a8aaf46 to your computer and use it in GitHub Desktop.
PasteBin shortcut for Hammerspoon
-- View your api_dev_key here: http://pastebin.com/api
local PASTEBIN_API_DEVELOPER_KEY = ""
-- Generate your api_user_key here: http://pastebin.com/api/api_user_key.html
local PASTEBIN_API_USER_KEY = ""
-- This makes a paste public or private, public = 0, unlisted = 1, private = 2
local PASTEBIN_API_PASTE_PRIVATE = "1"
--[[
There are 7 valid values available which you can use with the 'api_paste_expire_date' parameter:
N = Never
10M = 10 Minutes
1H = 1 Hour
1D = 1 Day
1W = 1 Week
2W = 2 Weeks
1M = 1 Month
--]]
local PASTEBIN_API_PASTE_EXPIRE = "1D"
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "P", function()
local board = hs.pasteboard.getContents()
local response = hs.http.asyncPost(
"http://pastebin.com/api/api_post.php",
"api_option=paste" ..
"&api_dev_key=" .. PASTEBIN_API_DEVELOPER_KEY ..
"&api_user_key=" .. PASTEBIN_API_USER_KEY ..
"&api_paste_private=" .. PASTEBIN_API_PASTE_PRIVATE ..
"&api_paste_expire_date=" .. PASTEBIN_API_PASTE_EXPIRE ..
"&api_paste_code=" .. hs.http.encodeForQuery(board),
{},
function(http_code, response)
if http_code == 200 then
hs.pasteboard.setContents(response)
hs.notify.new({title="Pastebin Paste Successful", informativeText=response}):send()
else
hs.notify.new({title="Pastebin Paste Failed!", informativeText=response}):send()
end
end
)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment