Using Applescript to Unmount and then spin down disks?

Discussion in 'Mac Programming' started by Inconsequential, Sep 13, 2011.

  1. Inconsequential macrumors 68000

    Sep 12, 2007
    Basic premise is:

    I have a WD Velociraptor that for most of the time does nothing. Mainly because it has windows on it, and unless VMWare Fusion is running it does nothing.

    Now due to some annoying things with OS X it doesn't spin down, therefore sits there using 5W all day long.

    Yes: The spin down HDs thing is ticked.

    This is also applicable to my MacBook Pro with an optibay on it. The SSD contains everything I use 95% of the time, the rest of the time the HDD in the bay spins needlessly, even when it's unmounted! :(

    I have an Applescript that unmounts them both but I need something to force them to spin down too.

    Is this possible? If so... how using Applescript (or something else which is triggered by Applescript)!?

  2. kainjow Moderator emeritus


    Jun 15, 2000
    I'm not sure if this is something that can be controlled directly.

    If you install Xcode, there is a utility called located at /Developer/Applications/Performance Tools/CHUD/Hardware Tools/ that shows the status of connected storage devices. For my external drive it shows "Active" when I can hear it spinning, and "Sleep" when it spins down.

    I am able to make it go into sleep by performing an eject on the device, which you can do via 'diskutil eject <dev>' where dev is the BSD name - obtained from 'diskutil list' or Disk Utility.

    I'm not sure if all devices support going to sleep when ejected, but you could certainly use AppleScript to run the eject command periodically if it works for yours.
  3. DESNOS macrumors 6502

    Aug 24, 2011
    This script should work nicely. It acts as a toggle. Save it as an application and you just need to run it when you want the disk to spin down. You need to run it again to access it, but it's a very fast process since it isn't a full "eject".

    set diskName to "Name Of Disk"
    tell application "Finder" to set diskExists to (disk diskName exists)
    if diskExists is true then
    	do shell script "diskutil umount " & quoted form of diskName
    	do shell script "diskutil mount " & quoted form of diskName
    end if
    Get the disk name from "diskutil list"

    99% of the time my code just sits here on these forums and looks pretty though. ^.^ Oh well. I enjoyed myself.
  4. xStep macrumors 68000

    Jan 28, 2003
    Less lost in L.A.
    I heard about Jettison the other day via a podcast. The user said it worked fine but didn't say much more.

Share This Page