Last active
December 11, 2022 02:12
-
-
Save zkarj735/3737a073b9288a0d6d60dbc8f494ce21 to your computer and use it in GitHub Desktop.
macOS shell scripts to list "ejectable" drives and to eject them all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Ejects "ejectable" drives. Use list_drives.sh to validate this will correctly identify and eject the drives you have. | |
df | egrep df | egrep '^(/dev/disk|exfat).+\s/Volumes' | sed -E 's|.+/(.+)|\1|' | sort | tr '\n' ' ' | sed -E 's|(.+) |💿 \1\n|' | sed -E 's|.+/(.+)|\1|' | xargs -n 1 diskutil eject |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Lists "ejectable" drive names on a single line, suitable for automation widgets. | |
df | egrep df | egrep '^(/dev/disk|exfat).+\s/Volumes' | sed -E 's|.+/(.+)|\1|' | sort | tr '\n' ' ' | sed -E 's|(.+) |💿 \1\n|' | sed -E 's|.+/(.+)|\1|' | sort | tr '\n' ' ' | sed -E 's|(.+) |💿 \1\n|' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment