ronaldoussoren / py2app

py2app is a Python setuptools command which will allow you to make standalone Mac OS X application bundles and plugins from Python scripts.
Other
340 stars 36 forks source link

Finder and "open with" #490

Open hasii2011 opened 1 year ago

hasii2011 commented 1 year ago

I am having the same problem trying to figure out what this guy on stack overflow asks:

https://stackoverflow.com/questions/73145905/how-to-receive-file-when-file-is-opened-in-python

Looked through Apple's plist documentation did not find any keys to help.

ronaldoussoren commented 1 year ago

I've posted an answer to that question, which is close to impossible to answer there due to lack of information.

In short, opening files in macOS by double clicking or dropping a file on the application icon results in a file open event (AppleEvents) that the application needs to handle. Most GUI libraries have a way convert those events into their regular event handling code.

You appear to be using wxWidgets, and that has some documentation on how to do this: https://wiki.wxwidgets.org/WxMac-specific_topics#File_associations. That package is targeting C++ code, but I expect that something similar can be done in Python code.