Ejecting USB drive via AppleScript does not make drive power down

applescriptcommand linedisk-utilityusb

On startup, I eject my external USB disks with the following AppleScript:

try
    do shell script "diskutil eject \"/Volumes/USB Backup\""
end try

This works as expected: the drive powers down. However, when my MacBook wakes from sleep (through not being used), the drive spins up – no partitions are mounted, but the drive is nonetheless on and humming. If I check the Disk Utility app, I see that the USB drives are all greyed out. If I right click one of the partitions and select "Eject Partition" (even though they are gray and thus symbolize that they are ejected) then the drive powers down.

It is however a little anoying to constantly have to go into Disk Utility, so I made though I could just re-execute my logon script. But that doesn't work.
Even if I modify it to work with the DeviceIdentifier

do shell script "diskutil unmountDisk disk1"

or

do shell script "diskutil eject disk1"

it doesn't work. Does anyone have a tip for me how I can power down the drive, so that this horrible humming stops?

Later Addition: I noticed something interesting. It has nothing to do with the laptop's sleep mode itself, but rather when my Cinema Display goes to sleep (after 1 min.). The USB drive is connected to the Cinema Display and every time the display "wakes up", the drive motor spins up. I have now tried to connect the USB drive to the MacBook Pro itself (who's sleep timer is at 30 min.) maybe this will solve the problem half-way.

Best Answer

For starters, the greyed-out appearance in Disk Utility means the disk is unmounted, not ejected. An ejected disk does not appear at all.

The reason it shows up is that when the Cinema Display wakes, the computer sees the drive show up just as if you'd plugged it in. (Honestly, I'm surprised it doesn't mount all the way and show up on the Desktop.)

One thing that can help (particularly in the case of your second script) is to use the internal disk identifier instead of the disk name. You can find the identifier by going into Disk Utility, selecting the disk (or partition) in question, and pressing the Info button (or hit +I). In that window, look at the label next to "Disk Identifier:". A disk (whole hard drive) would look like "disk0" or "disk2", a partition looks like "disk0s0", "disk0s2", or "disk2s1". Instead of using diskutil eject DriveName, use diskutil eject /dev/disk2s0.