Pass URL from Suggestion script to default script

Sharing and discussing custom actions for LaunchBar
Post Reply
jordi
Posts: 13
Joined: Thu Feb 19, 2009 6:43 pm

Pass URL from Suggestion script to default script

Post by jordi » Sun Jan 10, 2016 12:21 pm

Hi,

I've created a simple action to provide livesearch on tweakers.net/pricewatch. I've a suggestion.js that parses the returned JSON. On selecting one of the result items I want to open the URL that I get from the JSON. I'm not sure how to do this, since the title string is parsed to the default.js, even if I include the url in the JSON. I've attached the code. Can anyone point me in the right direction?

Thanks in advance!

Code: Select all

function run()
{
    // No argument passed, just open the website:
    LaunchBar.openURL('http://tweakers.net/pricewatch/');
}

function runWithString(argument)
{
    LaunchBar.openURL('http://tweakers.net/pricewatch/zoeken/?keyword=' + encodeURIComponent(argument));
}


Code: Select all

function runWithString(argument)
{
    var result = HTTP.getJSON('http://tweakers.net/xmlhttp/xmlHttp.php?application=sitewidesearch&type=search&action=pricewatch&output=json&keyword=' + encodeURIComponent(argument), 3);

    if (result == undefined) {
        LaunchBar.log('HTTP.getJSON() returned undefined');
        return [];
    }
    if (result.error != undefined) {
        LaunchBar.log('Error in HTTP request: ' + result.error);
        return [];
    }

    try {
        var suggestions = [];
   
      var i = 0
        for (i = 0; i < result.data.articles.length; i++) {
         var suggestion = result.data.articles[i];
         suggestions.push({
                             'title' : suggestion["name"],
                             'icon' : "icon.png",
                             'url' : suggestion["url"],
                             });
        }
        return suggestions;
    } catch (exception) {
        LaunchBar.log('Exception while parsing result: ' + exception);
        return [];
    }
}

JW123
Posts: 4
Joined: Sat May 21, 2016 12:21 am

Re: Pass URL from Suggestion script to default script

Post by JW123 » Sat May 21, 2016 12:21 am

Did you figure out how to do this? I'm trying to do the same thing.

JW123
Posts: 4
Joined: Sat May 21, 2016 12:21 am

Re: Pass URL from Suggestion script to default script

Post by JW123 » Sat May 21, 2016 3:36 am

Figured it out -- instead of using a suggestions script, enable "live feedback", and just return the results list from your default script. The behavior is similar, but those results can include "url" fields.

jordi
Posts: 13
Joined: Thu Feb 19, 2009 6:43 pm

Re: Pass URL from Suggestion script to default script

Post by jordi » Mon May 23, 2016 7:17 pm

I ended up running the exact same query again. It did the job. But I've used your approach with more recent actions as well. Unfortunately, when implementing actions with multi-level responses it doesn't play well with the live feedback enabled. I've attached a worklow I'm currently working on that queries IMDB using omdbapi.com. Maybe you can give it a try and let me know if live search works for you. If you right arrow into a movie title, you get more details, but in that case you can go one level up.
Attachments
IMDB.lbaction.zip
(90.63 KiB) Downloaded 177 times

Post Reply