Sorry, I replied before I saw your reply.
Here's the script I'm running. When I run a string like 'This-is a string with some stuff-in it' it correctly outputs: This\-is a string with some stuff\-in it.
But if I run the string 'But now my string|has pipes and 'quotes' nothing happens. it does work on the command line and correctly outputs the xml <items><item arg="But not my string|has pipes and \'quotes" uid="regexified" valid="yes"><title>But now my string|has pipes and \'quotes</title><subtitle>Copy to Clipboard</subtitle><icon /></item></items>
I want to keep pipes in there and un-escaped.
And no, I don't see any errors on the console.
# -*- coding: utf-8 -*-
import sys
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
args = sys.argv
string_to_regex = str(args[1]).decode('utf-8')
regexified = []
# Builds each part of the XML tree
def build_xmltree(items):
item = SubElement(items, 'item')
title = SubElement(item, 'title')
subtitle = SubElement(item, 'subtitle')
icon = SubElement(item, 'icon')
return (item, title, subtitle, icon)
for i in string_to_regex:
if i in ["-","\\","(",")",",","'",">","<"]:
regexified.append("\\"+ i)
else:
regexified.append(i)
alfred = ''.join(regexified)
alfred_two = alfred.encode('ascii', 'ignore')
items = Element('items')
item, title, subtitle, icon = build_xmltree(items)
item.set('uid', 'regexified')
item.set('arg', alfred_two)
item.set('valid', 'yes')
title.text = alfred
subtitle.text = 'Copy to Clipboard'
print tostring(items)