Skip to content

Instantly share code, notes, and snippets.

@tdlm
Last active March 29, 2019 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdlm/c5b0eb2ba4ef859be312 to your computer and use it in GitHub Desktop.
Save tdlm/c5b0eb2ba4ef859be312 to your computer and use it in GitHub Desktop.
URL Shortener shortcut for Hammerspoon
-- Requires an API Access Token from Bit.ly
local BITLY_API_ACCESS_TOKEN = ""
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "S", function()
local board = hs.pasteboard.getContents()
if board:match("^https?://") then
local response = hs.http.asyncGet(
"https://api-ssl.bitly.com/v3/shorten" ..
"?access_token=" .. BITLY_API_ACCESS_TOKEN ..
"&longUrl=" .. hs.http.encodeForQuery(board),
{},
function(status, response, headers)
if status == 200 then
local msg = hs.json.decode(response)
hs.pasteboard.setContents(msg.data.url)
hs.notify.new({title="Bitly URL Shorten: Success", informativeText=msg.data.url}):send()
else
hs.notify.new({title="Bitly URL Shorten: Failure", informativeText=response}):send()
end
end
)
else
hs.notify.new({title="Bitly URL Shorten: Failure", informativeText="Expected: URL"}):send()
end
end)
@surajsharma
Copy link

thank you!

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