MacOS eject all disks with a keyboard shortcut or the touch bar

In this post, you will first learn how to get a global shortcut and touchbar item to eject all disks connected to your MacBook at once and then learn how to create it yourself.

QUICK INSTALL

  1. Download and extract the automator script here

  2. Open the file and accept the installation of the quick action

    quick action installer window asks if eject all disks should be installed
  3. To add a global keyboard shortcut, go to <System Preferences> <Keyboard> <Shortcuts> <Services> and define a shortcut for "Eject all disks"

    system preferences keyboard to install a shortcut
  4. To make it accessible from the Touch Bar, go to <System Preferences> <Extensions> <Touch Bar> and check that "Eject all disks" is enabled. Then click on the Customize Control strip button…​ and add the <Quick Actions> item to your bar. After that, you can click the quick action button and select "Eject all disks" afterwards.

    customize control strip in the system extensions
    new quick action item in the touchbar

HOW IT WORKS

For people who do not trust the download above or simply want to know how it works, here’s the guide:

  1. Open <Automator> on your Mac and create a new document with Cmd + N or <File> <New>

  2. Choose <Quick Action> as the document type

  3. For <Workflow> select <no input> in <any application>

  4. Select an image. Click on <Choose…​>. Press Cmd + Shift + G to go to /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/. Select EjectMediaIcon.icns.

  5. Drag the action <Run AppleScript> to the right panel.

    guide to install the quick action eject all disk in the automator on your own
  6. Replace the code with this AppleScript

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    
    -- Defines a handler which tells Finder to eject all disks.
    to ejectAllDisk()
    	try
    		tell application "Finder"
    			-- Prevent unmounting full disks, those generally are mounted backup snapshots etc.
    			eject (every disk whose ejectable is true and free space is not equal to 0)
    		end tell
    		-- Display a system notification
    		display notification "You can now remove your disks safely." with title "Eject all disks" subtitle "Completed"
    	on error
    		display notification "Failed to eject all disks" with title "Eject all disks" subtitle "Failure"
    	end try
    end ejectAllDisk
    
    -- this is the entry method.
    on run
    	try
    		-- If the eject process takes longer than 3 seconds, tell the user that the operation is still in progress
    		with timeout of 3 seconds
    			ejectAllDisk()
    		end timeout
    	on error
    		display notification "Eject is still in progress" with title "Eject all disks" subtitle "Timeout"
    		-- Tell Finder to eject all disks again. This enables a success notification when the eject fails or succeeds
    		ejectAllDisk()
    	end try
    end run
  7. Save the Quick Action with name "Eject all disks"

  8. Follow steps 3 and 4 of quick install.