Alfred.app extension for shortening urls
#Desc: Shorten URL via is.gd, add to clipboard
#Use: isgd
#Ex: isgq http://example.com/long/url/to/shorten
CMD=$(php -f /usr/local/bin/isgd.php "{query}")
echo -n $CMD | pbcopy
echo -n $CMD
Screen shots
Main

Advanced

Requires the following code to be in /usr/local/bin/isgd.php
array("ignore_errors" => true));
$context = stream_context_create($opts);
if($shorturl)
$path = $basepath."&shorturl=$shorturl&url=$url";
else
$path = $basepath."&url=$url";
$response = @file_get_contents($path,false,$context);
if(!isset($http_response_header))
{
$result["errorMessage"] = "Local error: Failed to fetch API page";
return($result);
}
//Hacky way of getting the HTTP status code from the response headers
if (!preg_match("{[0-9]{3}}",$http_response_header[0],$httpStatus))
{
$result["errorMessage"] = "Local error: Failed to extract HTTP status from result request";
return($result);
}
$errorCode = -1;
switch($httpStatus[0])
{
case 200:
$errorCode = 0;
break;
case 400:
$errorCode = 1;
break;
case 406:
$errorCode = 2;
break;
case 502:
$errorCode = 3;
break;
case 503:
$errorCode = 4;
break;
}
if($errorCode==-1)
{
$result["errorMessage"] = "Local error: Unexpected response code received from server";
return($result);
}
$result["errorCode"] = $errorCode;
if($errorCode==0)
$result["shortURL"] = $response;
else
$result["errorMessage"] = $response;
return($result);
}
?>