问题
I am making an app in python, which is able to open different file types. This code is running fine on eclipse while passing filename which I want to open and configuration file as arguments respectively selectedFileName=(sys.argv)[1]
cfgFile=(sys.argv)[2]
. Now I converted this into application by using py2app. So, the issue is how to deal with arguments, as different file types need to be open through app and this app also needs configuration file while processing. Through py2app, in terminal passing this command open -a myapp.app selectedFileName config.cfg
opens the file as expected. But, What I want is to directly open file of any extension without the use of terminal. Is openwith
for opening file possible in this case, then how?. What changes I have to make in code for passing arguments for both? I also want to distribute this app to others.
回答1:
You can use py2app. It makes a standard app. All it needs is a python script and setup.py.
回答2:
Platypus
You might want to have a look at Platypus. It's intended to create Mac .app bundles from shell scripts. The documentation has some information on how to accept files that looks like it should be applicable to you. I haven't tested it out, but you should be able to run your script by dropping files onto the icon, and possibly using the Open With menu as well.
来源:https://stackoverflow.com/questions/19487291/how-to-convert-python-code-py-to-an-app-on-mac-osx