Jump to content
mcskrzypczak

[Alfred 3] No results in workflow with query text using diacritical letters

Recommended Posts

I have a weird problem with my workflow. It does not show any results in Alfred but works when run from Terminal. But let me explain more on that topic.
 
My workflow's job is to list Polish cities from webpage (get the list from JSON results from page) and download detailed weather forecast as png file. The main script is written in Python.
 
 
The thing is, Polish cites also uses diacritical letters (ą, ć, ę, ł, ń, ó, ś, ź, ż). And when I want to use my workflow with city that contain one or more of mentioned letters – say <code>Gdańsk</code> the workflow itself won't work – just shows the result prepared for situation when no results find.

 

However, when I debug the script from Terminal:

python script.py "Gdańsk"

I got all of the XML code for results:

<?xml version="1.0"?><items>
<item>
<arg>http://m.meteo.pl/warszawa/weather;Warszawa</arg>
<title>Ostatni → Warszawa</title>
<subtitle>Prognoza 60h. Wciśnij Cmd dla prognozy 84h.</subtitle>
<subtitle mod="cmd">Prognoza 84h.</subtitle>
</item>
<item autocomplete="Gdańsk">
<arg>http://m.meteo.pl/gdansk/weather;Gdańsk</arg>
<title>Gdańsk</title>
<subtitle>Prognoza 60h. Wciśnij Cmd dla prognozy 84h.</subtitle>
<subtitle mod="cmd">Prognoza 84h.</subtitle>
</item>
<item autocomplete="Nowy Dwór Gdański">
<arg>http://m.meteo.pl/nowy-dwor-gdanski/weather;Nowy Dwór Gdański</arg>
<title>Nowy Dwór Gdański</title>
<subtitle>Prognoza 60h. Wciśnij Cmd dla prognozy 84h.</subtitle>
<subtitle mod="cmd">Prognoza 84h.</subtitle>
</item>
<item autocomplete="Pruszcz Gdański">
<arg>http://m.meteo.pl/pruszcz-gdanski/weather;Pruszcz Gdański</arg>
<title>Pruszcz Gdański</title>
<subtitle>Prognoza 60h. Wciśnij Cmd dla prognozy 84h.</subtitle>
<subtitle mod="cmd">Prognoza 84h.</subtitle>
</item>
<item autocomplete="Starogard Gdański">
<arg>http://m.meteo.pl/starogard-gdanski/weather;Starogard Gdański</arg>
<title>Starogard Gdański</title>
<subtitle>Prognoza 60h. Wciśnij Cmd dla prognozy 84h.</subtitle>
<subtitle mod="cmd">Prognoza 84h.</subtitle>
</item>
</items>

Notice that first item group is previously used city. But all the other show results with name "Gdańsk".

 

And that is behavior, when the option in Script Filter – Alfred filters results is unchecked. When I check that, all seems to work fine. So why am I bothering you at all? Because I rather want to uncheck that option – it affects situations when I want to not display any results (in some cases).

 

So I want to ask you for help with that problem. Maybe there is some encoding problem in Alfred 3 itself?

 

The workflow can be downloaded here.

Just copy and paste "Gdańsk" to debug it.

Edited by Maciej Skrzypczak

Share this post


Link to post

Alfred's debugger will tell you more about what's wrong, but it's most likely an encoding issue.

The XML header should be <?xml version="1.0" encoding="utf-8"?>

And also make sure the XML is UTF-8 encoded.

In fact, at this point, you should probably forget about XML and uses Alfred 3's JSON support instead. There are far fewer things you can get wrong with JSON.

At any rate, if that doesn't help, you need to post the code that isn't working.

Edited by deanishe

Share this post


Link to post

Okay, so I replaced XML and use JSON instead and same thing happens.

 

When Alfred filters results is unchecked and I type city name with diacritical letter, like mentioned before "Gdańsk", the workflow shows result that it couldn't find any cities.

 

On the other hand, when Alfred filters results is checked I got results for "Gdańsk". However, when I type the name of the city that is not in the base like "London" the workflow behaves like there would be some problem, error (but debug window didn't show anything). In that case it should display result that it couldn't find any cities with such name.

 

As I mentioned in first post, Python script itself works without any errors. It has set coding to UTF-8 also. I have set the LC_CTYPE var to pl_PL.UTF-8 in Workflow Environment Variables but without any success.

 

Maybe that is Alfred bug when using diacritical letters?

 

Here is the script (to try it from Terminal you have to comment all that indicates to wdata variable as it depends on Alfred's own variables): link.

 
And here is updated workflow: link.
Edited by Maciej Skrzypczak

Share this post


Link to post

Firstly, the script doesn't run because the wdata/city file doesn't exist.

After getting it running, I'm not surprised the script doesn't work: you're mixing Unicode and encoded strings all over the place and trying to generate JSON by hand.

It doesn't work because your hand-coded JSON is invalid. Don't do that. Create a normal Python dictionary and then encode that with json.dump() instead.

json.dump(), OTOH, probably won't work because of all the encoded strings in your script.

Adding this to the top of your script may fix that: from __future__ import unicode_literals

Share this post


Link to post

Looking at your workflow, I think you misunderstand how Script Filters work.

 

If you select "Alfred filters results", then Alfred will call your workflow once with no query. Your script should then output all possible results to Alfred. Alfred filters them and calls your next action when the user chooses one.

 

You have to uncheck that box for your Script Filter.

 

Try this version.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...