3

So I have a lot of python scripts that I have written for my work but no one in my lab knows how to use Python so I wanted to be able to generate a simple Mac App where you can 'Browse' for a file on your computer and type in the name of the file that you want to save . . . everything else will be processed by the application for the python script I have generated.

Does anyone know if this is possible? I watched some tutorials on people generating applications in Xcode with Objective C but I don't want to have to learn a new language to reconstruct my Python scripts.

Thank you

3 Answers 3

1

If you only want this to run on OS X, you could use pyobjc (see https://stackoverflow.com/a/2393530) to develop a Cocoa application, but there are also quite a few cross-platform GUI frameworks for Python, which will work on OS X as well as other operating systems.

Sign up to request clarification or add additional context in comments.

Comments

1

For me, the easiest way to do this would be using the Automator program that comes with OSX. Create a new application, then choose Run Shell Script from within the Utilities sub-category. The pop-up at the top of the resulting window has a /usr/bin/python option. Put your python in there. You can connect inputs and outputs to that script using the Ask for Text item, etc...

The input from Ask for Text are most easily obtained if you choose "as arguments" from the Pass input: pop-up in the right of the Run Shell Script module. They come in as a list of strings, but not split on spaces like they would be in a normal line.

Try this code and I think it will become clear (for this test, put several strings separated by spaces as the text value that you pass):

import sys

print sys.argv
items = sys.argv[1:][0].split()

for f in items:
    print f

3 Comments

i'm not entirely sure how to connect the inputs to the variables in my functions ?
i went to 'Ask for Text' but it doesn't seem to link it to any text in my script. Also should I place my script after or in between import sys for f in sys.stdin: print f,
added a worked example to the answer above... (it is hard to debug those scripts inside the Automator editor...!)
0

Open Automator

Choose "Application"

Drag a "Run Shell Script" onto the workflow panel

Choose "/usr/bin/python" as the shell. Paste in your script, and select Pass Input: "to stdin"

Or, choose bash as the shell, and simply have the automator script run your Python script with Pass Input "as arguments" selected on the top right. You'll then use the contents of $@ as your arguments.

Save the application.

Done. You have a .app onto which files can be dragged.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.