Eject on Sleep


#1

Hello everyone... This is my first time on the forum so I thought I'd start with a simple little utility macro I made that helps avoid waking up to the million+ warning notices that sometimes pop up for external hard drives as the Mac does its power nap stuff during the night.

The AppleScript is not mine, it's pretty basic after all, but I like it in particular because it's a safe eject. If I've been using the external a lot I use the key shortcut first to make sure the eject is successful (it will just ignore actively used drives and go to sleep anyway). Otherwise I just hit the Sleep key combo before I go to bed and I don't have to worry about it.

Here's the AppleScript for copy and pasting: tell application "Finder" to eject ( every disk whose ejectable is true and local volume is true and free space is not equal to 0)

You can also preface it with Quit [Application] and a six second or so pause if you have an app that's always using your external (say iTunes or whatever).

If anyone knows how I can program the Sleep key combo (Command-option-eject) to a single key (say F12 or something) that would be great. When you try to record it it just puts the computer to sleep...


#2

Hi @TheWesterner,

Welcome to the forum, and thanks for sharing your macro. To answer this question:

The answer is, you don't need to have the macro type the system Sleep shortcut. Keyboard Maestro includes a native action for sleeping your computer:

image

Another tip, if I may: when posting AppleScript code here, you can, and ideally should, post it like this:

```applescript
[SCRIPT]
```

Doing so will cause it to be nicely formatted in a distinctive manner from the rest of the post, like this:

tell application "Finder" to eject (every disk whose ejectable is true and local volume is true and free space is not equal to 0)

#3

Welcome to the forum, and thanks for sharing your macro