The title basically says what I'm trying to do.
I have a python script using deanishe's alfred-workflow library that I'm using to build an ssh CLI string.
Workflow is set up like this:
The Script Filter runs "python jump.py {query}", or attempts to.
jump.py looks like the following, and is meant to take args such as "9999,192.168.100.100,50.57.203.223", and buildout 'query', which should be passed to the Terminal Command action of "ssh {query}
def main(wf):
if len(wf.args):
query = wf.args[0]
else:
query = None
print query
log.debug(query)
arglist = query.split(',')
randport1 = random.randint(5000,7000)
randport2 = random.randint(5000,7000)
port = arglist[0]
srv1 = arglist[1]
srv2 = arglist[2]
query = "-A -t -L 9800:localhost:{0} -L {1}:localhost:{2} user@{3} ssh -L {4}:localhost:9800 -L {5}:localhost:80 user@{6}".format(randport1,port,randport2,srv1,randport1,randport2,srv2)
wf.add_item(
title = "Jump from %s to %s" % (srv1,srv2),
arg = "-A -t -L 9800:localhost:{0} -L {1}:localhost:{2} user@{3} ssh -L {4}:localhost:9800 -L {5}:localhost:80 user@{6}".format(randport1,port,randport2,srv1,randport1,randport2,srv2),
valid = True
)
wf.send_feedback()
# Mainloop
if __name__ == u"__main__":
wf = Workflow()
log = wf.logger
sys.exit(wf.run(main))
This is the debug output I get... I'm not terribly familiar with XML, so I don't know what's going on here. The confusing thing is I have another script that is identical in the way it takes the args passed through Alfred, splits them into a list, and then assigns it to key value pairs in a dict. It works fine..
<?xml version="1.0" encoding="utf-8"?>
<items><item valid="no"><title>Error in workflow 'com.alfred.custconn'</title><subtitle>list index out of range</subtitle><icon>/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns</icon></item></items>
[STDERR: alfred.workflow.input.scriptfilter] 15:18:37 jump.py:28 DEBUG 9999,11.48.54.65,11.11.11.1
[INFO: alfred.workflow.input.scriptfilter] 9999,192.168.100.100,50.57.203.223
[ERROR: alfred.workflow.input.scriptfilter] XML Parse Error 'The operation couldn’t be completed. (NSXMLParserErrorDomain error 4.)'. Row (null), Col (null): 'Document is empty' in XML:
9999,192.168.100.100,50.57.203.223
<?xml version="1.0" encoding="utf-8"?>
<items><item valid="yes"><title>Jump from 192.168.100.100 to 50.57.203.223</title><subtitle /><arg>-A -t -L 9800:localhost:6678 -L 9999:localhost:5025 user@192.168.100.100 ssh -L 6678:localhost:9800 -L 5025:localhost:80 user@50.57.203.223</arg></item></items>