Jump to content
Ahti333

Let Script Filters output Feedback multiple times

Recommended Posts

This is best explained with an example:

 

The Amazon Suggest and Google Suggest workflows work fine on fast internet connections.

On a slow connection however, it can take a noticable amount of time to load the suggestions.

To make those Workflows more usable, i tried to alter them to output the input value as first feedback item, and do that before any connection is even made. The problem now is, that the output of a script is only read once, when the script finished executing. This python script:

 

import time

xml = """
<items>
	<item uid="0" arg="~/Desktop" valid="YES" autocomplete="Desktop" type="file">
 	   <title>Desktop0</title>
 	   <subtitle>~/Desktop</subtitle>
 	   <icon type="fileicon">~/Desktop</icon>
	</item>
"""

print(xml)

time.sleep(5)

xml = """
	<item uid="0" arg="~/Desktop" valid="NO" autocomplete="Desktop" type="file">
 	   <title>Desktop1</title>
 	   <subtitle>~/Desktop</subtitle>
 	   <icon type="fileicon">~/Desktop</icon>
	</item>
	<item uid="0" arg="~/Desktop" valid="YES" autocomplete="Desktop2" type="file">
 	   <title>Desktop2</title>
 	   <subtitle>~/Desktop</subtitle>
 	   <icon type="fileicon">~/Desktop</icon>
	</item>
</items>
"""

print(xml)

 

outputs all items, but does so only after 5 seconds, while i think the expected behaviour would be to output the first item immediately, and then the other ones after 5 seconds.

 

A related problem I have is that when a script outputs multiple <items> groups, only the first one is processed. If Alfred would only read the last one, and combined with the previous problem, a script could also change feedback items while it is running.

Share this post


Link to post
Share on other sites

This is best explained with an example:

 

The Amazon Suggest and Google Suggest workflows work fine on fast internet connections.

On a slow connection however, it can take a noticable amount of time to load the suggestions.

To make those Workflows more usable, i tried to alter them to output the input value as first feedback item, and do that before any connection is even made. The problem now is, that the output of a script is only read once, when the script finished executing. This python script:

 

import time

xml = """
<items>
	<item uid="0" arg="~/Desktop" valid="YES" autocomplete="Desktop" type="file">
 	   <title>Desktop0</title>
 	   <subtitle>~/Desktop</subtitle>
 	   <icon type="fileicon">~/Desktop</icon>
	</item>
"""

print(xml)

time.sleep(5)

xml = """
	<item uid="0" arg="~/Desktop" valid="NO" autocomplete="Desktop" type="file">
 	   <title>Desktop1</title>
 	   <subtitle>~/Desktop</subtitle>
 	   <icon type="fileicon">~/Desktop</icon>
	</item>
	<item uid="0" arg="~/Desktop" valid="YES" autocomplete="Desktop2" type="file">
 	   <title>Desktop2</title>
 	   <subtitle>~/Desktop</subtitle>
 	   <icon type="fileicon">~/Desktop</icon>
	</item>
</items>
"""

print(xml)

 

outputs all items, but does so only after 5 seconds, while i think the expected behaviour would be to output the first item immediately, and then the other ones after 5 seconds.

 

A related problem I have is that when a script outputs multiple <items> groups, only the first one is processed. If Alfred would only read the last one, and combined with the previous problem, a script could also change feedback items while it is running.

 

It's not what you want, but in my version of Google Suggest (and similar workflows) I timeout the network request at 1 second. If the request times out, I just give back what was typed by the user.

Share this post


Link to post
Share on other sites

One second is still quite a bit. What bothers me specifically is that i can not just put in a search term and hit enter when i am not interested in suggestions. I still have to wait for the connection to load or time out.

Share this post


Link to post
Share on other sites

One second is still quite a bit. What bothers me specifically is that i can not just put in a search term and hit enter when i am not interested in suggestions. I still have to wait for the connection to load or time out.

 

I'm confused by this. You CAN just enter you term and press Enter if you don't want suggestions. Goggle Suggestions is a workflow that you would have installed and opted to use by entering a keyword into Alfred before you started typing your query. The Google Suggestions workflow cannot be set as default.

Share this post


Link to post
Share on other sites

in case of google that may be true, but there are other cases (amazon) where this does not apply, and i't like to have only one keyword for both applications, and either way it would be very nice if alfred supported this as i am sure there are many other applications for changing the output results multiple times during a potentially long script run

Share this post


Link to post
Share on other sites

in case of google that may be true, but there are other cases (amazon) where this does not apply, and i't like to have only one keyword for both applications, and either way it would be very nice if alfred supported this as i am sure there are many other applications for changing the output results multiple times during a potentially long script run

 

Even the amazon suggest is still a workflow that has to be specifically executed with a keyword. If you enter a query in Alfred, it either generates matches or doesn't. If it doesn't you should be provided with one or more fallback searches (that you can change in the preferences). The default is Google, Amazon, and Wikipedia. These are not suggestions, they just perform a search. Even you type something that does match, you can still setup a modifier key to perform a default web search instead of action whatever it found. This can be setup in the Advanced preferences in Alfred.

Share this post


Link to post
Share on other sites

maybe, but that is all talk about specific searches/workflows.

 

in general, as workflow developer, i want to be able to output and change feedback items multiple times during one run of a script.

Share this post


Link to post
Share on other sites

maybe, but that is all talk about specific searches/workflows.

 

in general, as workflow developer, i want to be able to output and change feedback items multiple times during one run of a script.

 

You were saying that you didn't always want suggestions. That sometimes you just want to type your query and not get results, just perform the search. I was simply saying that to do that, you simply need not use the suggest workflows. They are optional.

 

If I'm understanding your request, the ability to output and change feedback multiple times isn't currently available in Alfred. This sounds like you want to have a script filter, get feedback, and have that tied to another script filter, and chain several together. Currently, the only way to do something like this would be to set up another script filter, and make the end result of the first one run Alfred again with the keyword and query pre-populated in the search field. This can be done with AppleScript. 

tell application "Alfred 2" to search "query here.."

Share this post


Link to post
Share on other sites

no, that is not what i want.

 

a script filter runs a script.

that script outputs xml data describing the feedback items.

 

my problem is that the output of this script is read (and the according items are displayed) only once, when the script has finished running.

 

take a look at the example script i posted in the first post in this topic. what it does is it outputs the xml for one feedback item, then waits five seconds, and then outputs xml for another two feedback items. the behaviour i would like to have is that alfred immediately, as the script is started, displays the first item, and then when after five seconds the other two items get printed and the script exits, displays those too.

 

the other thing that is linked with this is that alfred only interprets the forst <items> group a script prints, while i think it would be better to only show the feedback items from the last group the script printed.

Share this post


Link to post
Share on other sites

no, that is not what i want.

 

a script filter runs a script.

that script outputs xml data describing the feedback items.

 

my problem is that the output of this script is read (and the according items are displayed) only once, when the script has finished running.

 

take a look at the example script i posted in the first post in this topic. what it does is it outputs the xml for one feedback item, then waits five seconds, and then outputs xml for another two feedback items. the behaviour i would like to have is that alfred immediately, as the script is started, displays the first item, and then when after five seconds the other two items get printed and the script exits, displays those too.

 

the other thing that is linked with this is that alfred only interprets the forst <items> group a script prints, while i think it would be better to only show the feedback items from the last group the script printed.

 

Ah gotcha. So.. this has come up in the past in different ways. We've got a note to explore other ways to accomplish things like this. Several people have wanted to throttle the XML output, delay until typing has stopped, not execute at every typed character, etc.

 

Thanks for the recommendation. 

Share this post


Link to post
Share on other sites

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

×