Kevin Gao
Kevin Gao

Reputation: 61

Bundle a python script into an OS X App, but

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?

Upvotes: 2

Views: 1565

Answers (3)

svth
svth

Reputation: 1310

You could prompt for input using the GUI via AppleScript. Just invoke /usr/bin/osascript, show a window with a text field and return it.

See here for an example (albeit in Perl)

Upvotes: 0

S.Lott
S.Lott

Reputation: 392050

What's the best way to get user input

Don't mess with a "bundled" 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.

Upvotes: -1

regulus6633
regulus6633

Reputation: 19040

@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.

Upvotes: 2

Related Questions