Jump to content

Veritas3241

Member
  • Posts

    6
  • Joined

  • Last visited

Everything posted by Veritas3241

  1. This script worked exactly like I need it to. I'm a complete noob at dealing with all of the encoding issues. I'm still trying to wrap my head around it all. For now, I'm going to use the script like you wrote it, but I still might try my hand incorporating one of the libraries. Thank you very much for your help!
  2. Shawn, good call. That was part of the problem. Tyler, thanks for pointing that out. I think I'll work on this and incorporate the alp library. I hadn't seen that before and it might solve some of my other problems. Thank you both very much! You've been very helpful!
  3. 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)
  4. Now that I play with the code some more, it seems that certain characters are not liked by Alfred. My string has pipes |, apostrophes, and other fun characters in it. Is there a way to have alfred ignore those?
  5. It does work fine on the command line. I have to wrap my string in quotes to get it to work but the one I'm testing (and works on the command line) is 1192 characters. I wonder if it's an issue with encoding? I'm going from utf-8 to ascii within the script. Might it also be an issue with copying into the alfred argument field? The workflow right now is type 'reg', and copy my string in. I don't type it in.
  6. I'm building a workflow that will accept a string input and output the same string with some characters escaped using '\'. This is so the string can be accepted into a function which accepts regular expressions. I have a python script that does this perfectly and Alfred will do it perfectly as well up to about 60-70 characters. After that it just defaults to the "Search Google for {my string}". My question is a) is there a character limit on arguments passed into Alfred and is there a way to bypass it? Thank you!
×
×
  • Create New...