Reduce the action to mount your EFI partition to just a simple keyboard shortcut.
Here's the process I used to put everything together, been using it on my system without issue.
-
In terminal:
1.) Open a new terminal window and enter 'diskutil list' and keep the identifier handy. Should look something like disk0s1.
Note: We will now make changes to the sudoers permissions, try not to fuck up here. If you aren't familiar with how this works I recommend you give this a read and familiarize yourself with the controls for vi/vim.
2.) Create a new file in sudoers.d to allow execution of 'diskutil mount' and 'diskutil umount' on a specific partition without requiring a sudo password. Make sure the label/identifier is correct for your system. Replace USERNAME with your username or group;
In a new terminal window, enter the command 'sudo visudo -f /etc/sudoers.d/efimnt'. Press ESC, then press I and paste/rewrite this into the file (Tab over after Cmnd_Alias and USERNAME);
Cmnd_Alias EFIMNT = /usr/sbin/diskutil mount /dev/disk0s1, /usr/sbin/diskutil umount /dev/disk0s1 USERNAME ALL = (ALL) NOPASSWD:EFIMNT
Once you're done with that press ESC, and then enter these keys/commands to save: ':wq'. This will let you save changes, if you fuck up here it should give you the option to correct any syntax errors.
3.) Once complete, enter the command 'sudo -l' to verify these changes, should appear as such;
User USERNAME may run the following commands on SystemName: (ALL) ALL (ALL) NOPASSWD: /usr/sbin/diskutil mount /dev/disk0s1, /usr/sbin/diskutil umount /dev/disk0s1
The order this prints is important, you want to see the commands we just added printed last. If (ALL) ALL appears last then you will not have nopasswd execution of these commands and the automation will error out (error listed below in 4.1).
In Automator:
1.) Open Automator and create a new document, set the type as Quick Action.
2.) In Automator, set the workflow to receive no input in any application.
3.) Drag and drop the action Run Shell Script into the open workspace and copy this script into the empty text field. Make sure the disk label/identifier is correct for your system;
if mount | grep /dev/disk0s1 > /dev/null; then sudo /usr/sbin/diskutil umount /dev/disk0s1 else sudo /usr/sbin/diskutil mount /dev/disk0s1 fi
4.) Press Run to give this a quick function check to verify everything works so far.
4.1.) If you encounter this error:
The action "Run Shell Script" encountered an error: "sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper. sudo: a password is required"
...then something went wrong while creating the sudoers.d file. Mind the order files are loaded, check the syntax for errors or make sure this file loads last from sudoers.d (or add this into an existing file under a new command alias).
5.) If this works as intended and your EFI partition mounts and un-mounts for each run, then congratulations. You can save the action with any name and/or customize the icon and color.
In System Preferences:
1.) Navigate to Keyboard, select the Shortcuts tab and then select the Services menu.
2.) At the bottom of the list, under General, you should see the action you just created.
3.) Assign any key combination you like, though if you encounter issues try combinations that include the Command (⌘) key. I currently have this set to Shift+Command+E.
-
Helpful resources:
If you run into issues while creating the sudoers.d file, give this and this a quick read.
This is the guide I got most of my information from, the code I provide checks disk mount status and allows for the toggling function.
Feel free to point out if this method is dogshit, or is a security risk. I'm no stranger to linux and unix/unix-like OS's but I'm not an expert. I also cannot attest to this functioning properly on systems with dualboot setups or those with multiple disk drives that are added/removed. I've been using this on a laptop with macOS as the primary OS.