λ ryan. himmelwright. net

Easily Ejecting macOS Disks

- from a plane between RDU and Seattle

A macOS dock with a purple finder icon selected
I can easily ejects my disk by clicking a single dock icon.

I particularly enjoy my laptop setup, which includes connecting it to a dock that supports multiple SSDs. This arrangement streamlines my backup process and provides additional storage space for infrequently used large files like games, local large language models (LLMs), and virtual machine disk images.

However, I hate how macOS yells at me when I abruptly unplug the dock. It has the right to nag… I wouldn’t want to yank the cord in the middle of a Time Machine backup. Nevertheless, I’m still too lazy to manually eject all the drives each time I disconnect.

Solution

An Apple Shortcuts edit window with an apple script for its only command
Editing the shortcut. It just runs the AppleScript.

So, I devised a solution to streamline this process. It’s not original, and in fact, I adapted elements from various online resources to create it. Unfortunately, too much time has passed, and I’ve lost track of the specific sources I used.

In short, I configured an Apple Shortcut to disconnect known disks from my Mac using Apple Script:

tell application "Finder"
 -- Get a list of all ejectable disks
 set ejectableDisks to every disk whose ejectable is true
 
 -- Loop through each disk and check its name
 repeat with aDisk in ejectableDisks
  if name of aDisk is "MasterBall" or name of aDisk is "PokeBall" then
   eject aDisk
  end if
 end repeat
end tell

This script:

This approach ensures the script doesn’t accidentally eject disk images or drives I might want to keep connected once undocked.

Lastly, I added the shortcut to my dock. Now, I just tap an icon and those drives eject. Easy.

Conclusion

So far, it has performed excellent. Occasionally, I have to wait a few seconds for it to complete, but that’s likely due to the system waiting for the disks to eject, and isn’t really avoidable.

I have thought about adding a physical smart button to trigger the script, but the required complexity to accomplish that hasn’t been worth the effort yet 😅 . Right now, this is perfect.

- Back to Post Index -