Jump to content

google url shortener


Recommended Posts

I was trying to turn Mike Walker's url shortener extension into an Alfred 2 Workflow but failed. Anyone else know how to do this? Here is the link to the extension: http://incredimike.com/projects/alfred-gurl/

 

You would do it like this:

 

Screenshot_3_14_13_2_27_PM-5.jpg

 

And the script would look like this:

 

 

# longURL supplied by user
$longUrl = "{query}";
 
# Use commandline curl because it's good at these sort of things
$resp = `curl --silent https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d '{"longUrl": "$longUrl"}'`;
 
# Use JSON extension added in PHP 5.2
$json = json_decode( $resp );
 
# Echo out the URL.
echo $json->id;
Link to comment

Thanks macbookandrew and of course Mike for the initial shortener (even though there was already one ;))

 

Thanks of course Andrew and Vero too.

 

There are many reasons to love Alfred and this is just one example - the first url shortener I used stopped working, quick Google and got Mikes version (much quicker than diagnosing/testing etc.). Then v2 Alfred comes round, url shortener and snippets gone! I upgraded early. Very short time later import doodads sorted out. Done that, then quick hunt and shortener found (here).

 

No wonder Alfred receives so much love. Deservedly so.

 

R!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...