Applescript 检测新驱动器

发布于 2024-07-27 19:42:13 字数 283 浏览 13 评论 0 原文

我有一个 applescript studio 应用程序,用于对硬盘驱动器进行成像。 现在,它运行 shell 脚本 (diskutil list -plist) 来获取有关连接到计算机的驱动器的信息,然后将此信息呈现给用户,并选择正确的驱动器进行映像。

理想情况下,我希望我的应用程序能够检测何时插入新设备,并提示用户对该驱动器进行映像。

我正在考虑循环运行 shell 脚本并比较结果以检测新设备是否可用,但这似乎会浪费大量 CPU。 applescript 是否有办法监听某种事件并检测新设备可用?

I have an applescript studio application that I use for imaging hard drives. Right now it runs a shell script (diskutil list -plist) to get information about the drives attached to the computer, it then presents this information to the user, and the proper drive to image is selected.

Ideally I would like my application to be able to detect when new devices are plugged in, and prompt the user to image that drive.

I was thinking about running the shell script in a loop and comparing the results to detect if a new device is available, but that seems like that would waste a lot of CPU. Is there someway for applescript to listen to some sort of event and detect that a new device is available?

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

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

发布评论

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

评论(1

最后的乘客 2024-08-03 19:42:13

AppleScript (Studio) 无法注册任何系统通知,通知只能在 Objective-C 中完成。
顺便说一句,DiskArbitration.framework 比 diskutil 快得多。

另一种方法可以是文件夹操作或观察 /Volumes 的 launchd 代理。
但是将信息传递到主应用程序是相当迂回的

希望这有帮助

AppleScript (Studio) is not able to register to any system notification, notifications can only be accomplished in Objective-C.
By the way DiskArbitration.framework is much faster than diskutil.

An alternative could be a folder action or a launchd agent which observes /Volumes.
But it's quite circuitous to pass the information to the main application

Hope this helps

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