MacOSX带有应用程序的打开文件:它在哪里? [英] MacOSX open file with an application: where does it go to?

查看:83
本文介绍了MacOSX带有应用程序的打开文件:它在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我之前发布了这个基本问题,但没有得到我可以使用的答案.

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

我一直在Mac上编写应用程序,并且实际上将它们制作成.app捆绑包 (即,手动制作目录和plist文件).但是,当我通过右键单击finder中的文件并指定我的应用程序在应用程序中打开文件时,该如何引用该文件?

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?

我主要使用python,但是我正在寻找一种相当通用的方法.

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_#######'

文件引用在哪里?

预先感谢

推荐答案

文件由Apple Event传递,请参见

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.

如果您的脚本不是GUI应用程序,但是如果您只想通过单击将文件传递给Python脚本,则最简单的方法是使用Automator.有一个名为"Run Shell Script"的操作,您可以在其中指定解释器和代码.您可以选择是否通过stdin或自变量接收文件名. Automator会为您将脚本打包到应用程序中.

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.

这篇关于MacOSX带有应用程序的打开文件:它在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆