views:

81

answers:

2

I have a python script bundled into a application (I'm on a mac) and have the application set to be able to open .zip files. But when I say "open foo.zip with bar.py" how do I access the file that I have passed to it?

Additional info: Using tkinter.

What's a good way to debug this, as there is no terminal to pass info to?

A: 

If I'm not greatly mistaken, it should pass the name of the file as the first argument to the script - sys.argv[1].

Matthew Iselin
That's what I would think too... only, regardless of whether I specify a file or not, `sys.argv[1]` is filled with "-psn_0_#######"
Skyler
+1  A: 

You should be using sys.argv[1]

task = sys.argv[1].decode('utf-8')
if task == u'uppercase':
    pass
elif task == u'openitems':
    item_paths = sys.argv[2:]
    for itempath in item_paths:
        itempath = itempath.decode('utf-8')
pyfunc
I'm a little unsure about this. It generates syntax errors on my machine. What is it trying to accomplish?
Skyler
Idea is to decode the input gathered through «sys.argv» as UTF-8 first. The same we have to do, if we have to send a value to applescript. What will be passed to bar.py is a command, which needs to be decoded. Commands can be subsequently handled as shown in example above.
pyfunc
Don't forget to `import sys`
domen
Yeah .. Thats right , I simply took the code piece that illustrates it, removing the rest.
pyfunc
sys.argv[1] is filled with -psn_0_****** so that doens't work anyway
Skyler