The first thing you have to do is sign up for an account on bit.ly if you haven't already, next you have to obtain an API key. You can sign up for a bit.ly account at: http://bit.ly/a/sign_up if you already have an account you can get your API key at: http://bit.ly/a/your_api_key.
First create a shell script called shorten.sh:
#!/bin/bash
curl -s "http://api.bitly.com/v3/shorten?login=YOURLOGIN&apiKey=YOURAPIKEY&longUrl=$1&format=txt" | pbcopy
This script uses curl in silent mode to connect to the bit.ly API and shorten the url specified by longUrl. Since we want to shorten a variety of URLs I've used $1, which refers to the first argument the script was invoked with. You'll also notice the format parameter, this can be set to xml, json or txt, we're using txt so we don't have to do any parsing. We are piping the output of our curl command into pbcopy a command line utility provided by OS X which provides copying to the clipboard. Pbcopy basically copies all output it receives into the clipboard.
Make sure to fill in YOURLOGIN with your bit.ly login and YOURAPIKEY with your bit.ly API key. Save the shell script somewhere it's not going to be deleted by accident or moved. If you use bash open your .bash_profile file in your home directory. You may have to create it if you haven't made any changes to it before. Add the following line:
alias shorten='/bin/bash /PATHTOSCRIPT/shorten.sh'
Where PATHTOSCRIPT is the path to where you have stored your script. This alias will allow us to invoke our script from anywhere using "shorten" instead of the full path to the script. In order for your .bash_profile to be reloaded and the alias to become active, you need to either type source .bash_profile or open a new terminal window.
Now when you type:
shorten YOURURL
Where YOURURL is any URL you wish to shorten, the shortened version will be copied directly into your machine's clipboard.
effin awesome.
ReplyDeletethis comment uncrowded by many not-quite-on-topic questions (motivated by personal projects, whose daydreams are often set bombastic soundtracks, & references aloud often end with "& then all will bow down before me,") to save its author (me) the embarrassing realization of just how silly they in fact might very well seem. that would hurt my, uh, score.
the above metaphor nonetheless allows information to be disclosed on the suspicion that you know exactly what i mean.
thanks! you made my day -- rereading man pages does not always work, perhaps especially when one starts out only knowing the nothing sandbox that corporate eulas drool to keep invisibly locked.... and besides, it was not so much the commands as the strategies --
be seeing you...
Great stuff! Just added my own domain to bitly and this will make it way more simpler to shorten URLs.
ReplyDeleteCool. I could extend it a little bit :) Instead of using $1, use pbpaste. It will paste the original url into the script. One step less :) Heres the code:
ReplyDeleteurl=$(pbpaste)
curl -s "http://api.bitly.com/v3/shorten?login=YOURLOGIN&apiKey=YOURAPIKEY&longUrl=$url&format=txt" | pbcopy
Additional, if you put this into an automator app, you can access es via spotlight or Alfred & Co.
But, what one major problem is faced by most of the people is the long URL. They not only like to ignore the long URL but also find out the ways to shorten them. url shortener
ReplyDeleteWow what a Great Information about World Day its very nice informative post. thanks for the post.
ReplyDeleteShortener
Maybe their most concerning issue is that is doesn't resemble a URL by any means. Except if you're acquainted with running from monkeys in the Mideast. tinyurl
ReplyDeleteIt is safe to say that you are utilizing a link shortener yet for your site links and offshoot links? If not, you ought to be!bitly
ReplyDeletecosì come è non potremmo mai sapere in quanti lo hanno scaricato. Dobbiamo quindi andare su Google.gl e incollarlo nel campo apposito quindi andare su Shorten URL. Si otterrà questo indirizzo accorciato url shortener
ReplyDeleteVery useful information and thanks for sharing. Donald’S Office Mod Apk
ReplyDelete