4

我希望我的应用程序从可移动存储设备运行,它应该获取运行它的可移动存储的路径或启动应用程序的 rem 存储设备。我已经看到 nsworkspace 获取可移动存储设备的路径,但不知道如何在运行时获取路径。

请提出一种方法来做到这一点。我也搜索了网络并知道mac系统上没有自动运行功能。我希望我的应用程序在将可移动存储连接到 mac 系统时自动启动。有什么解决方法吗?

谢谢

4

2 回答 2

10

[[NSBundle mainBundle] bundlePath]将为您提供 .app 包装器的路径。

从那里,您需要使用NSFileManagerAPI 来枚举卷并确定您的应用程序在哪个卷上,以及它是否符合您的可移动性标准。Snow Leopard 中的 API 已显着更新。

旁白;这对应用程序来说是一个明显奇怪的要求。非典型的,至少可以这么说。

于 2009-09-02T21:33:19.283 回答
5

To your second question of an autorun feature, there are several techniques for detecting that a volume has been mounted and then using that to trigger an action (like launching a program). But all of them require that your software has already been installed so that you can run a daemon to watch for volume mounts. I am not suggesting that a program should do such a thing (it almost never should), but it is a technique. I suspect this is not what you're asking.

随着 OS X 的发布,让系统自动运行基于卷挂载的某些东西的可疑功能已被删除。几乎无法想象重新添加这种行为。这是对各种滥用行为的邀请,对用户几乎没有好处。OS X 将在挂载新卷时打开一个 Finder 窗口,您可以自由地为您的根目录提供有用的背景图像,以指导用户如何启动您的应用程序。

于 2009-09-02T21:59:34.270 回答