Jump to content

Iterative script filter responses


Recommended Posts

Hi :wub: ,

 

I created a custom *script filter* which performs multiple queries against a distant webservice. Like the "Google Suggest" example, I first get a list of entries from the service (one fast request), but then I perform two additional queries (slow ones) *per item* which I use as *subtitle* and *icon*.

 

Even by limiting to 9 items and caching results, it is slow. It wonder if it's possible (and how) to send a first XML response to Alfred immediately and send another response later (when I have performed all the requests) to replace the first one.

 

For illustration, using the "Google Suggest" example, imagine that for each suggestion I want to show as subtitle the URL of the first result when searching with Google and the associated favicon. The script would first send to Alfred (immediately after getting suggestions):

<?xml version="1.0"?>
<items>
    <item uid="1.1364323823" arg="alfred" valid="yes" autocomplete="">
        <title>alfred</title>
        <subtitle>Search Google for alfred</subtitle>
        <icon>icon.png</icon>
    </item>
    <item uid="2.1364323823" arg="alfred hitchcock" valid="yes" autocomplete="">
        <title>alfred hitchcock</title>
        <subtitle>Search Google for alfred hitchcock</subtitle>
        <icon>icon.png</icon>
    </item>
    <item uid="3.1364323823" arg="alfred university" valid="yes" autocomplete="">
        <title>alfred university</title>
        <subtitle>Search Google for alfred university</subtitle>
        <icon>icon.png</icon>
    </item>
</items>

and some 2-3 seconds later change the result to (with more information):

<?xml version="1.0"?>
<items>
    <item uid="1.1364323984" arg="http://www.alfredapp.com/" valid="yes" autocomplete="">
        <title>alfred</title>
        <subtitle>alfredapp.com/</subtitle>
        <icon>favicons/www.alfredapp.com.png</icon>
    </item>
    <item uid="2.1364323984" arg="http://en.wikipedia.org/wiki/Alfred_Hitchcock" valid="yes" autocomplete="">
        <title>alfred hitchcock</title>
        <subtitle>en.wikipedia.org/wiki/Alfred_Hitchcock</subtitle>
        <icon>favicons/en.wikipedia.org.png</icon>
    </item>
    <item uid="3.1364323984" arg="http://www.alfred.edu/" valid="yes" autocomplete="">
        <title>alfred university</title>
        <subtitle>http://www.alfred.edu/</subtitle>
        <icon>favicons/www.alfred.edu.png</icon>
    </item>
</items>

I tried sending two results (via standard output) to Alfred but only the first is shown.

 
Thank you :ph34r:.
Link to comment

Hi :wub: ,

 

I created a custom *script filter* which performs multiple queries against a distant webservice. Like the "Google Suggest" example, I first get a list of entries from the service (one fast request), but then I perform two additional queries (slow ones) *per item* which I use as *subtitle* and *icon*.

 

Even by limiting to 9 items and caching results, it is slow. It wonder if it's possible (and how) to send a first XML response to Alfred immediately and send another response later (when I have performed all the requests) to replace the first one.

 

For illustration, using the "Google Suggest" example, imagine that for each suggestion I want to show as subtitle the URL of the first result when searching with Google and the associated favicon. The script would first send to Alfred (immediately after getting suggestions):

<?xml version="1.0"?>
<items>
    <item uid="1.1364323823" arg="alfred" valid="yes" autocomplete="">
        <title>alfred</title>
        <subtitle>Search Google for alfred</subtitle>
        <icon>icon.png</icon>
    </item>
    <item uid="2.1364323823" arg="alfred hitchcock" valid="yes" autocomplete="">
        <title>alfred hitchcock</title>
        <subtitle>Search Google for alfred hitchcock</subtitle>
        <icon>icon.png</icon>
    </item>
    <item uid="3.1364323823" arg="alfred university" valid="yes" autocomplete="">
        <title>alfred university</title>
        <subtitle>Search Google for alfred university</subtitle>
        <icon>icon.png</icon>
    </item>
</items>

and some 2-3 seconds later change the result to (with more information):

<?xml version="1.0"?>
<items>
    <item uid="1.1364323984" arg="http://www.alfredapp.com/" valid="yes" autocomplete="">
        <title>alfred</title>
        <subtitle>alfredapp.com/</subtitle>
        <icon>favicons/www.alfredapp.com.png</icon>
    </item>
    <item uid="2.1364323984" arg="http://en.wikipedia.org/wiki/Alfred_Hitchcock" valid="yes" autocomplete="">
        <title>alfred hitchcock</title>
        <subtitle>en.wikipedia.org/wiki/Alfred_Hitchcock</subtitle>
        <icon>favicons/en.wikipedia.org.png</icon>
    </item>
    <item uid="3.1364323984" arg="http://www.alfred.edu/" valid="yes" autocomplete="">
        <title>alfred university</title>
        <subtitle>http://www.alfred.edu/</subtitle>
        <icon>favicons/www.alfred.edu.png</icon>
    </item>
</items>

I tried sending two results (via standard output) to Alfred but only the first is shown.

 
Thank you :ph34r:.

 

What you are requesting currently isn't available in Alfred. Alfred only uses a single XML output to show results. The only way to change that result is for the script to fire again (result of changing the input string).

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...