macos 如何在 Mac OS X 上通过 USB 连接或 CD 插入自动运行应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/410583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:00:15  来源:igfitidea点击:

How do I automatically run an application on USB attach or CD insert on Mac OS X?

macosusbautorun

提问by Yigang Wu

Is there any way to automatically launch an application on USB attach or CD insert on Mac OS X? it's easy on Windows, but I found that AutoRun.Infdoes not work on the Mac at all.

有没有办法在 Mac OS X 上通过 USB 连接或 CD 插入自动启动应用程序?在 Windows 上很容易,但我发现这AutoRun.Inf在 Mac 上根本不起作用。

回答by Sophie Alpert

You can't. Autostarting applications is impossible under Mac OS X.

你不能。在 Mac OS X 下无法自动启动应用程序。

The next-best thing, opening the CD folder and showing the installer icon, can be done by using (AutoOpen version 1.0) to make a .dmgwhich can then be burnt to a CD.

接下来最好的事情是打开 CD 文件夹并显示安装程序图标,可以通过使用(AutoOpen 1.0 版)制作一个.dmg可以刻录到 CD 的文件。

回答by Mike Heinz

Don't know why you were voted down - this is a common question for Windows programmers looking at Macs.

不知道为什么您被否决了 - 这是 Windows 程序员在查看 Mac 时的常见问题。

Basically, auto-run is considered a security problem and so is not supported in OSX. Sophie (formerly known as Ben) Alpert's answer is also a bit overkill. Most installers for OSX simply open up a folder to show the application and, possibly, a readme. Installing is done by dragging the app to your Applications folder.

基本上,自动运行被认为是一个安全问题,因此在 OSX 中不受支持。Sophie(原名Ben)Alpert的回答也有点矫枉过正。大多数 OSX 安装程序只是打开一个文件夹来显示应用程序,可能还有一个自述文件。安装是通过将应用程序拖到您的应用程序文件夹来完成的。

For other kinds of apps on CDs (say, a slide show or something like that), the developer generally uses hidden folders to hide support data to ensure that the only thing the user will see when they open the CD is the single icon they're supposed to double click to start the app.

对于 CD 上的其他类型的应用程序(比如幻灯片或类似的东西),开发人员通常使用隐藏文件夹来隐藏支持数据,以确保用户打开 CD 时唯一看到的是他们的单个图标。重新应该双击启动应用程序。

回答by Eduard Feicho

It is possible to install a background service that monitors whenever a USB device is plugged in and then launches an App. Google's "Android File Transfer Agent" is such a service that is running in the background and launches "Android File Transfer" whenever you plug in an Android device.

可以安装后台服务,在插入 USB 设备时进行监控,然后启动应用程序。Google 的“Android 文件传输代理”就是这样一种服务,它在后台运行并在您插入 Android 设备时启动“Android 文件传输”。

回答by JavaCoderEx

If you are looking for something for just yourself, you could write a small mac app that runs in the background and watches for a particular USB device (by id) to be attached and then run the program. Ideally a small XML plist could be used to map device IDs to the correct program to run. The XCode SDK has sample code that monitors for device additional and removal to get you started.

如果您只是为自己寻找一些东西,您可以编写一个在后台运行的小型 mac 应用程序,并监视要连接的特定 USB 设备(通过 id),然后运行该程序。理想情况下,可以使用一个小的 XML plist 将设备 ID 映射到要运行的正确程序。XCode SDK 具有示例代码,可监控设备的添加和删除以帮助您入门。

回答by tc0nn

I agree with JavaCoderEx. I would crontab a task that looks for /Volumes/*/autorun.sh, then runs it once. Maybe touch a file in /tmp/ so you know its already been run, then remove it if the volume disappears.

我同意 JavaCoderEx。我会 crontab 一个查找 /Volumes/*/autorun.sh 的任务,然后运行它一次。也许触摸 /tmp/ 中的文件,以便您知道它已经运行,然后在卷消失时将其删除。