MacOSX open file with application: where does it go?

I asked this basic question before, but did not receive an answer with which I could work.

I write applications on my Mac and physically paste them into .app packages (i.e. manually create directories and plist files). But when I open the file in the application, right-clicking on the file in finder and indicating my application, how can I then refer to this file?

I mainly use python, but I'm looking for a way that is pretty universal.

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

Py:

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

Where is the link to the file?

Thanks in advance,

+3
source share
5 answers

Apple Event, . Apple. Python script. PyObjC script, , Apple Objective-C, Python.

script , Python script, , Automator. "Run Shell Script", . , stdin . Automator script .

+4

, . @Sacrilicious :

@Sacrilicious - . , python script, "". 4- python script: myscript.app/Contents/MacOS/myscript -

file = open("/tmp/test.txt", "w")
file.writelines(sys.argv[1:])

"". " " myscript.app.

/tmp/text.txt, , - -psn_0_#######, , "open with". , Apple Events, .

, , , python script, OS X .app, - , Bounty:)

+2

, / ?

~/Library/Preferences/com.apple.LaunchServices.plist

launchservices, - "" 10.6 ( ) ObjectiveC Python Ruby. Python , .

0
source

I have never heard this done without Cocoa / Carbon wrapper.

0
source

I described how to associate certain types of files with Python applications included in py2app at https://moosystems.com/articles/8-double-click-on-files-in-finder-to-open-them-in-your -python-and-tk-application.html

0
source

Source: https://habr.com/ru/post/1763709/


All Articles