如何使用通过 NSTask 启动的应用程序打开文档?
我已经厌倦了内置的 open
Mac OS X 命令,主要是因为它使用您的实际用户 ID 而不是有效用户 ID 运行程序;这导致 sudo open Foo
使用您的帐户而不是 root
帐户打开 Foo 及其关联应用程序,这让我很烦恼。所以我决定进行某种替代。
到目前为止,我已经成功了:我可以在 open -a
或 open -b
方式下打开任何程序,并且支持选择性等待。我正在使用 NSTask 来实现此目的。
但是,我也希望能够打开文档。据我所知,您需要使用 NSWorkspace
来执行此操作,但是使用 NSWorkspace
启动程序会导致使用您帐户的凭据而不是命令行程序的凭据启动它们证书。这正是默认的 open
工具所做的,也是我不想要的。
那么,如何在不使用 NSWorkspace 的情况下让程序请求另一个程序打开文档呢?从 NSTask
对象中,我可以获得进程 ID,但仅此而已。
I've grown tired of the built-in open
Mac OS X command, mostly because it runs programs with your actual user ID instead of the effective user ID; this results in the fact sudo open Foo
opens Foo with its associated application with your account instead of the root
account, and it annoys me. So I decided to make some kind of replacement.
So far I've been successful: I can open any program under the open -a
or open -b
fashion, and support optionally waiting. I'm using NSTask
for that purpose.
However, I'd like to be able to open documents too. As far as I can see, you need to use NSWorkspace
for that, but using NSWorkspace
to launch programs results in them being launched with your account's credentials instead of your command line program's credentials. Which is precisely what the default open
tool does, and precisely what I don't want.
So, how can I have a program request that another program opens a document without using NSWorkspace
? From the NSTask
object, I can have the process ID, but that's about it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望这能解决问题:
Hopefully this will do the trick: