tags:

views:

21

answers:

1

I posted this basic question before, but didn't get an answer I could work with.

I've been writing applications on my Mac, and have been physically making them into .app bundles (i.e., making the directories and plist files by hand). But when I open a file in the application by right clicking on the file in finder and specifying my app, how do I then reference that file?

I mostly use python, but I'm looking for a way that is fairly universal.

My first guess was as an argument, as were the answers to my previous post, but that is not the case.

Py:

>>> print(sys.argv[1:])
'-psn_0_#######'

Where is the file reference?

Thanks in advance,

+1  A: 

The file is passed by the Apple Event, see this Apple document. You need to receive that from inside your Python script. If it's a PyObjC script, there should be a standard way to translate what's explained in that Apple document in Objective-C to Python.

If your script is not a GUI app, but if you just want to pass a file to a Python script by clicking it, the easiest way would be to use Automator. There's an action called "Run Shell Script", to which you can specify the interpreter and the code. You can choose whether you receive the file names via stdin or the arguments. Automator packages the script into the app for you.

Yuji
Thanks. I will look into that.
Skyler