Mac – Mac equivalent for UDEV folder on linux

bashmac

I am writing a script which should backup my Documents folder onto a USB stick. I want the script to be executed every time I connect the USB stick. I found a solution here. But it seems like I can't find the folder where to put the rule.

So does anyone know where I could find a udev or rules folder?

Best Answer

udev doesn't exist on OS X. As an alternative, you can use the diskutil activity command to continuously monitor disks being mounted or ejected. The diskutil man page says

Continuously display system-wide disk manipulation activity as reported by the Disk Arbitration framework until interrupted with a signal (e.g. by typing Control-C). This can be useful to watch system-wide activity of disks coming on-line or being ejected, volumes on disks being mounted or unmounted, volumes being renamed, etc.

Whilst running the above command and plugging in (then removing) my WD Elements USB drive, I get this output, which could be parsed (even though the man page says not to) to find, say, DiskMountApproval and DiskDisappeared to get the volume name and when the disk was added and removed.

***DiskPeek ('disk2') Time=20120331-11:56:22.7716
***DiskPeek ('disk2s1') Time=20120331-11:56:23.0801
***DiskAppeared ('disk2', DAVolumePath = '<null>', DAVolumeKind = '<null>', DAVolumeName = '<null>') Time=20120331-11:56:23.0810
***DiskMountApproval ('disk2s1', DAVolumePath = '<null>', DAVolumeKind = 'hfs', DAVolumeName = 'Elements') Comment=Approving Time=20120331-11:56:23.0820
***DiskAppeared ('disk2s1', DAVolumePath = 'file://localhost/Volumes/Elements/', DAVolumeKind = 'hfs', DAVolumeName = 'Elements') Time=20120331-11:56:23.2574
***DAIdle (no DADiskRef) Time=20120331-11:56:23.2576
***DiskUnmountApproval ('disk2s1', DAVolumePath = 'file://localhost/Volumes/Elements/', DAVolumeKind = 'hfs', DAVolumeName = 'Elements') Comment=Approving Time=20120331-11:56:44.2338
***DiskDescriptionChanged ('disk2s1', DAVolumePath = '<null>') Time=20120331-11:56:44.4515
***DAIdle (no DADiskRef) Time=20120331-11:56:44.4518
***DiskEjectApproval ('disk2') Comment=Approving Time=20120331-11:56:44.4542
***DiskDisappeared ('disk2', DAVolumePath = '<null>', DAVolumeKind = '<null>', DAVolumeName = '<null>') Time=20120331-11:56:50.1964
***DiskDisappeared ('disk2s1', DAVolumePath = '<null>', DAVolumeKind = 'hfs', DAVolumeName = 'Elements') Time=20120331-11:56:50.1970
***DAIdle (no DADiskRef) Time=20120331-11:56:50.1972