Skip to content

Instantly share code, notes, and snippets.

@chrischan514
chrischan514 / eject.py
Last active August 17, 2023 21:37
One-key eject all external storage devices from macOS (works with external hard drives and USB devices, not tested with disc drives)
#!/usr/bin/python
import os,re, subprocess
diskUtilList = os.popen('diskutil list').read()
externalPhysicalRegEx = r".*\/dev\/(disk((?:\d+))) \(external\, physical\).*"
extDiskIntRegex = r".*\/dev\/disk(\d+) \(external\, physical\).*"
diskList = re.findall(extDiskIntRegex, diskUtilList)