Mac OS X
On Mac OS X you can use Automator to create an application that calls your python app and passes the input file path as a string argument. In the application workflow wizard, add action "Run Shell Script", select Pass input:
as as arguments
, and in the text box add:
python /path/to/my/app/myapp.py "$@"
The "$@"
passes along whatever arguments were in the input (aka the selected file) as strings. As long as your script is set up to deal with the input (sys.argv
) as a list of strings (the first one being the python app path), then it will work.
When you save that Automator workflow, it is treated by OS X like any other app, and you can set that app as the default for files of type "*.foo". To associate "*.foo" with that app, right click a .foo file, Get Info
, Open with: Other...
, choose the app you created in Automator, then click the Change All...
button.
Windows
A similar but hopefully less-involved approach might work in Windows. You could probably create a batch file (.bat
) with the following:
python C:pathomyappmyapp.py %*
The %*
expands to all arguments.
As long as you can associate a file extension with that batch file, then you could do that, and that's your solution. However, I haven't tried this Windows solution, so take it with a grain of salt. The Mac solution, on the other hand, I have tested.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…