Skip to content

Instantly share code, notes, and snippets.

@tdlm tdlm/pastebin.lua
Last active Jan 11, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.