开发者

How to run a script on device mount in OSX

开发者 https://www.devze.com 2022-12-20 00:08 出处:网络
I want to make a script that automatically backs up my kindle files when I connec开发者_如何学运维t it to my macbook pro.Writing the script is well within my ability, but I don\'t know what\'s the bes

I want to make a script that automatically backs up my kindle files when I connec开发者_如何学运维t it to my macbook pro. Writing the script is well within my ability, but I don't know what's the best way to run a script on mount automatically.


You could either use AppleScript and attach a folder action to the /Volumes directory, or you could write a Launch Agent that watches that path.

For the latter, you can refer to Tutorial: Backups with Launchd on MacResearch. The gist of it is that you create a plist configuration file to be interpreted by launchd; then launchd will execute your script when the specified path has changed.


What kind of scripting did you have in mind? If you are using AppleScript, would it be possible to attach a folder action to the /Volumes directory (or maybe the specific subdirectory on which the Kindle mounts) to back up the files? I've never tried something like that, so use the idea at your own risk, but for what it's worth...

Other than that, I don't know of a general way to run a script on a mount in OS X. Kevent, which is OS X's version of Linux's inotify, would be a way something like that might be accomplished, but obviously you don't want to write a C program for all of this. One might be out there though.

0

精彩评论

暂无评论...
验证码 换一张
取 消