我有一个 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?
发布评论
评论(1)
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