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?
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