A minimal, safe, and interactive Python utility that lists and formats external drives on macOS using the native diskutil command.
Overview
- Lists connected disks and prompts the user to choose one for formatting.
- Supports ExFAT (recommended) and FAT32.
- Uses macOS’ built-in
diskutilfor reliable disk operations. - Includes confirmation prompts to reduce risk of accidental data loss.
Requirements
- macOS
- Python 3.7 or later
- Administrator privileges (required to run
diskutilerase operations)
Quick start
- Clone the repository:
git clone https://github.com/<your-username>/macos-drive-formatter.git cd macos-drive-formatter
- (Optional) Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate - Run the script:
python3 format_external_drive.py
Usage summary
- The script runs
diskutil listto display available disks. - Enter the disk identifier (for example:
disk4). - Confirm the selected disk (explicit
yrequired). - Choose the filesystem format:
- 1 → ExFAT (recommended: cross-platform)
- 2 → FAT32 (legacy compatibility)
- Provide an optional volume name (defaults to
MyUSB). - Confirm the final destructive action before the script invokes
diskutil eraseDisk.
Example session === macOS External Drive Formatter ===
🔍 Listing available disks...
/dev/disk4 (external, physical): #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *30.9 GB disk4 1: Linux 28.2 GB disk4s3
Enter the disk identifier (e.g. disk4): disk4
Choose the filesystem format:
- ExFAT (recommended)
- FAT32 (for legacy systems)
Enter your choice (1 or 2): 1
Enter a name for the new volume (e.g. MyUSB): BackupDrive
This will ERASE all data on the disk. Proceed? (y/n): y
✅ Disk /dev/disk4 formatted successfully as ExFAT (BackupDrive)
How it works
The script delegates formatting to diskutil:
diskutil eraseDisk ExFAT MyUSB GPT /dev/disk4
This leverages macOS's native disk management for compatibility and reliability.
Safety & disclaimers
- This tool will irreversibly erase data on the selected disk.
- Double-check the disk identifier before confirming.
- The author is not responsible for data loss caused by misuse.
Development & contributions
- Contributions and improvements are welcome. Open an issue or pull request with suggested changes.
- Future enhancements may include additional filesystem support (APFS, HFS+), a GUI, and progress reporting.
Author
Dabwitso Mweemba — Co-founder & Lead Developer at Code Savanna
GitHub • LinkedIn
License This project is released under the MIT License. See the LICENSE file for details.