Skip to content

Instantly share code, notes, and snippets.

@zkarj735
Last active December 11, 2022 02:12
Show Gist options
  • Save zkarj735/3737a073b9288a0d6d60dbc8f494ce21 to your computer and use it in GitHub Desktop.
Save zkarj735/3737a073b9288a0d6d60dbc8f494ce21 to your computer and use it in GitHub Desktop.
macOS shell scripts to list "ejectable" drives and to eject them all
#!/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
#!/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