在运行时获取应用程序的路径 +可可

发布于 2024-08-03 15:02:39 字数 214 浏览 12 评论 0原文

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

请建议一种方法来做到这一点。我也在网上搜索了一下,发现mac系统上没有自动运行功能。我希望我的应用程序能够在可移动存储连接到 Mac 系统时自动启动。有什么解决方法吗?

谢谢

i want my application to run from removable storage devices and it should get the path of the removable storage it is running from or the rem storage device from which the app is launched.
I have seen nsworkspace to get path of removable storage device but dont know how to get the path at run time.

please suggest a way to do this. also i have searched the net and came to know that there is no autorun feature on mac systems. I want my app to auto launch itself whenever a removable storage is attached to a mac system. is there any workaround for this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海夕 2024-08-10 15:02:39

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

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

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

[[NSBundle mainBundle] bundlePath] will give you the path to your .app wrapper.

From there, you'll need to use the NSFileManager APIs to enumerate the volumes and figure out which one your app is on and whether it meets your criteria for removable-ness. The APIs have been updated significantly in Snow Leopard.

An aside; this is a distinctly odd requirement for an application. Atypical, to say the least.

厌味 2024-08-10 15:02:39

对于自动运行功能的第二个问题,有几种技术可以检测卷是否已安装,然后使用它来触发操作(例如启动程序)。但所有这些都要求您已经安装了软件,以便您可以运行守护程序来监视卷安装。我并不是建议程序应该做这样的事情(它几乎不应该),但它是一种技术。我怀疑这不是你要问的。

随着 OS X 的发布,让系统自动运行基于卷安装的某些内容的可疑功能已被删除。重新添加这种行为几乎是不可想象的。这会引发各种各样的滥用行为,但对用户来说几乎没有什么好处。当安装新卷时,OS X 将打开一个 Finder 窗口,您可以自由地为根目录提供有用的背景图像,以指导用户如何启动您的应用程序。

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.

The questionable feature of having the system automatically run something based on a volume mount was removed with the release of OS X. It is almost inconceivable that such a behavior would be re-added. It is an invitation to a wide variety of abuses, with very little benefit for the user. OS X will open a Finder window when a new volume is mounted, and you are free to provide a helpful background image for your root directory that will instruct the user on how to launch your app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文