Last active
March 29, 2019 12:08
-
-
Save tdlm/c5b0eb2ba4ef859be312 to your computer and use it in GitHub Desktop.
URL Shortener shortcut for Hammerspoon
This file contains 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
-- 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you!