Skip to content

Instantly share code, notes, and snippets.

@iCross
Last active August 29, 2015 14:13
Show Gist options
  • Save iCross/39ff51f4a6b19ffdad14 to your computer and use it in GitHub Desktop.
Save iCross/39ff51f4a6b19ffdad14 to your computer and use it in GitHub Desktop.
--- This will take a url on your clipboard, and use google to shorten it
--- create a new text expander item, set to applescript and paste this in.
--- set your google developer api key :
set myKey to "XXXXXXXXXXXXXXXXXXXXXXXXXX"
set the ClipURL to (the clipboard as string)
ignoring case
if ((characters 1 through 4 of ClipURL as string) is not "http") then
return "Malformed URL."
else
set curlCMD to ¬
"curl -sX POST -H 'Content-Type: application/json' -H 'Accept-Encoding: gzip' -H 'User-Agent: gzip' -d '{\"longUrl\": \"" & ClipURL & "\" }' 'https://www.googleapis.com/urlshortener/v1/url?fields=id&key=" & MyKey & "' --compressed"
-- Run the script and get the result:
set grepCMD to "grep -o '://goo.gl[^\"]*'"
set forecast to do shell script curlCMD & " | " & grepCMD
set forecast to "https" & forecast
return forecast
end if
end ignoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment