Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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