This repository was archived by the owner on Oct 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
j-wilkins edited this page Mar 8, 2012
·
5 revisions
Welcome to the short wiki!
This really only serves one purpose, a place to toss this handy applescript for Launchbar I just hacked from the instapaper one I found.
To use it, open Launchbar, type till you find this script, then hit spacebar and put whatever url you want to shorten in there then hit return. If you have growl running, you'll get a message with the shortened url and it will be copied to your clipboard.
I can get syntax highlighting working, but then all my \\'s get weird...
on handle_string(_url)
set _short_url to "http://shortener1.heroku.com"
set cmd to "curl -sF shortener={\\\"url\\\":\\\"" & _url & "\\\"} " & _short_url & "/add.json"
set _rtnCode to do shell script cmd
tell application "System Events" to set _growlIsRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
if (_growlIsRunning) then
growlRegister()
growlNotify(_rtnCode, _short_url)
else
set code to offset of "\"success\":true" in _rtnCode
if (code is equal to 0) then
display dialog "Error
Well shit. "
end if
end if
end handle_string
-----------------------------------
-- Growl Part
-----------------------------------
on growlRegister()
tell application "Growl"
register as application "LaunchBar" all notifications {"Success", "Error"} default notifications {"Success", "Error"} icon of application "LaunchBar.app"
end tell
end growlRegister
on growlNotify(_rtnCode, _short_url)
set code to offset of "\"success\":true" in _rtnCode
if (code is not equal to 0) then
set short_start to (offset of "\"shortened\"" in _rtnCode) + 13
set short_end to (offset of "\"url\"" in _rtnCode) - 3
set _short to (characters short_start thru short_end of _rtnCode) as string
set _shortened_url to _short_url & "/" & _short
set _gTitle to "Success"
set _gText to "Saved link successfully.
Url: " & _shortened_url
set the clipboard to _shortened_url
else
set _gTitle to "Error"
set _gText to "Unkown Error. srlsy wtf."
end if
tell application "Growl"
notify with name _gTitle title "Short" description _gText application name "LaunchBar"
end tell
end growlNotify