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
-
Download and extract the automator script here
-
Open the file and accept the installation of the quick action
-
To add a global keyboard shortcut, go to <System Preferences> <Keyboard> <Shortcuts> <Services> and define a shortcut for "Eject all disks"
-
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.
HOW IT WORKS
For people who do not trust the download above or simply want to know how it works, here’s the guide:
-
Open <Automator> on your Mac and create a new document with Cmd + N or
<File> <New>
-
Choose <Quick Action> as the document type
-
For <Workflow> select <no input> in <any application>
-
Select an image. Click on <Choose…>. Press Cmd + Shift + G to go to
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/
. SelectEjectMediaIcon.icns
. -
Drag the action <Run AppleScript> to the right panel.
-
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
-
Save the Quick Action with name "Eject all disks"
-
Follow steps 3 and 4 of quick install.