@Espresso
Edit:
Here's your workflow modified to do exactly what you were aiming for: https://drive.google.com/file/d/1eX_pa_E3thrMvdKVKzYDpjrKyOT2oLyS/view?usp=sharing
I haven't edited the python script at all, just re-arranged and edited some stuff in the workflow editor.
Now it looks like this:
For a crude explanation of how it works, refer below:
Before edit:
The following workflow does precisely what you've described:
https://github.com/mr-pennyworth/alfred-gif
I know you want to write your own, so, you can take a look at this workflow and see how it is done and do the same in your own workflow. Here's how it achieves the behavior you described:
This is a script filter. As @deanishe mentioned, in a script filter, you can't do wait-for-enter. So, I do this hack instead: The script filter basically does no work except for storing the query in a file. When the user presses enter, (2) and (3) are activated simultaneously.
Returns immediately with a "search in progress..." message.
Gets results from the gif website, returns a message about the gif.
The messages from (2) or (3) are stored in an environment variable.
Re-populate Alfred's search box with the query that was just executed.