Skip to content

Instantly share code, notes, and snippets.

@perifer
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perifer/fde4f6827e4e9417a9c9 to your computer and use it in GitHub Desktop.
Save perifer/fde4f6827e4e9417a9c9 to your computer and use it in GitHub Desktop.
Asynchronous Javascript Action
// Adopted from
// http://www.obdev.at/resources/launchbar/developer-documentation/javascript-http.html#//apple_ref/cpp/Method/getJSON
function run(done) {
var search = 'perfect circle';
var query = encodeURIComponent(search);
var result = HTTP.getJSON('http://ws.spotify.com/search/1/artist.json?q=' + query, function(result) {
if (result.data != undefined) {
// Show the top result:
var artist = result.data.artists[0];
done([{ 'title' : artist.name}]);
} else if (result.error != undefined) {
LaunchBar.alert('Unable to load results for "' + search + '"', result.error);
done();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment