views:

52

answers:

2

I currently have a script that I'm using to update files for me from a couple repositories. The script works fine if I execute it using:

python myscript.py

However, when I attempt to bundle into an App, it no longer functions correctly because a part of my script requires user input. There is no interface, however, for it to use. I've tried bundling it with py2applet, Platypus (with the Text output), but I haven't been able to find a way to get input working.

someVar = raw_input("Enter some file name here: ")

So, my question is: What's the best way to get user input from a bundled python app?

+1  A: 

What's the best way to get user input

Don't mess with a "budled" app. Just use the command line.

Tell your user to open a terminal window and run your app from the command line. Saves everyone a lot of pain.

Users don't "need" bundled apps. They can type. Try it.

S.Lott
add `#!/usr/bin/python` as first line to your script. run `chmod +x path_to_your_script/myscript.py ` and put the script in some directory which is in the `PATH` environment varibale. Then everyone can run the script by just calling `myscript.py`. You can even remove the `.py` to make it look like all the other command line tools.
jigfox
Thanks for the advice. I would love if people could just learn how to use the command line, but I feel like the reality is that many people don't *want* to. For now, I will go with your suggestions, but for the sake of learning, is there any way of going about the original request?By the way, I am currently using<code>#!/usr/bin/env python</code>as my shebang. Is there any benefit to using <code>#!/usr/bin/python</code> besides saving a few characters?
I actually thought <code>#!/usr/bin/env python</code> was a bit more robust.
Nothing's really going to change. Python will probably always stay at /usr/bin/python, so it doesn't really matter.
Josso
+1  A: 

@sudowork: For now, I will go with your suggestions, but for the sake of learning, is there any way of going about the original request?

You can pass arguments into a python script so you don't need the python script to actually get them. Get them in your cocoa app instead. Ask for the inputs in the cocoa app, then run the python script using NSTask like you would any other command line program and pass in the arguments. Here's how you get the passed args in the python script. The first arg can be gotten with this...

someVar = sys.argv[1]

To bundle the python script just add it to your project. Make sure the script has the shebang and is executable as explained above. You'll probably have to manually force it to be added to your app bundle by adding a new "copy files" build phase and adding the script to that.

regulus6633