alpo Posted February 26, 2014 Share Posted February 26, 2014 Hi guys, I've been trying to return some results from a Python-based workflow. While it kind of works, when selecting one of the items, the corresponding file doesn't open. What am I doing wrong? <?xml version="1.0"?> <items> <item arg="/Users/apopescu/Dropbox/ka/nvall/qq-Git tags.md" uid="Gittags" valid="yes" type="file"> <title>Git tags:</title> <subtitle>Find the closest tag related to the specific commit:</subtitle> </item> </items> Thanks a lot, :- a Link to comment
Tyler Eich Posted February 26, 2014 Share Posted February 26, 2014 That XML looks valid. Could you upload your workflow? That would make diagnosing the problem much easier Link to comment
alpo Posted February 26, 2014 Author Share Posted February 26, 2014 Here's the main script: https://gist.github.com/al3xandru/e10547141f9e3c47179c I've added the workflow as a Script filter python $HOME/bin/qq.py "{query}" Link to comment
smarg19 Posted February 26, 2014 Share Posted February 26, 2014 Just a guess from the code, but you may need to escape your file path argument. That is, the space in the file name doesn't look properly encoded in the xml. So, when you select that item, you are looking for "/Users/apopescu/Dropbox/ka/nvall/qq-Git", which obviously doesn't exist. Link to comment
deanishe Posted February 26, 2014 Share Posted February 26, 2014 It's possible that you've got the escaping wrong in your Open File action. Are you sure you've selected "Escape spaces"? An important tip, however: you should not be generating the XML the way you're doing (using string formatting). Use one of the XML libraries built into Python. xml.etree.ElementTree is the common choice. This will output the XML you posted, and will not break if a file path has <, > or & in it (which your script absolutely will): from xml.etree import ElementTree as ET root = ET.Element('items') item = ET.SubElement(root, 'item', {'arg': u'/Users/apopescu/Dropbox/ka/nvall/qq-Git tags.md', 'uid': u'Gittags', 'valid': 'yes', 'type': 'file'}) ET.SubElement(item, 'title').text = u'Git tags:' ET.SubElement(item, 'subtitle').text = u'Find the closest tag related to the specific commit:' print ET.tostring(root).encode('utf-8') Note that I've preceded every string that could contain non-ASCII characters with u, to tell Python that it's Unicode, not ASCII. Link to comment
jdfwarrior Posted February 27, 2014 Share Posted February 27, 2014 Hi guys, I've been trying to return some results from a Python-based workflow. While it kind of works, when selecting one of the items, the corresponding file doesn't open. What am I doing wrong? <?xml version="1.0"?> <items> <item arg="/Users/apopescu/Dropbox/ka/nvall/qq-Git tags.md" uid="Gittags" valid="yes" type="file"> <title>Git tags:</title> <subtitle>Find the closest tag related to the specific commit:</subtitle> </item> </items> Thanks a lot, :- a This XML is valid. A good test for things like this is to create a simple workflow, add a script filter and 'cat' the XML string to see if it gives you a result. If you are running a script file, I would suggest trying to run it from the terminal and see if there are any errors or other output associated with the script aside from the XML Link to comment
alpo Posted February 27, 2014 Author Share Posted February 27, 2014 @smarg19: I've tried escaping but made no difference. @deanishe: why? @David: I've checked the output multiple times and I cannot spot any errors (that's the reason I've posted here). I'll take an example output and `cat` it. What if it doesn't work? What would be the next thing to look into? Link to comment
deanishe Posted February 27, 2014 Share Posted February 27, 2014 (edited) Why what? If the cat works, your script is probably throwing an error (and not sending output to Alfred). Run the script in Terminal to see what happens. Edited February 27, 2014 by deanishe Link to comment
alpo Posted February 27, 2014 Author Share Posted February 27, 2014 @deanishe: 1. why using ElementTree instead of templates? (I'm aware of the possible escaping issues) 2. the script doesn't throw errors... I've tested this repeatedly. Link to comment
deanishe Posted February 27, 2014 Share Posted February 27, 2014 WRT 1: Basically because generating valid XML can be tricky, but with an XML library, somebody else (who's smarter than you and me) has done the hard work for you. Using string templates to generate XML is a recipe for disaster, and it will almost certainly come back to bite you in the backside at some point. WRT 2: Then you're going to have to post your actual workflow. You've posted valid XML and say your workflow throws no errors. There's not much more anyone can say without some code to poke a stick at. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now