Clean & eject external drives in macOS
There have been a host of macOS utilities over the years that remove macOS hidden system and metadata files from external drives in order to prevent compatibility issues on devices like MP3 players, car stereos, etc.:
CleanEject: "Remove unwanted hidden files on USB-sticks, cameras, GPSses and other devices"
Eject-for-Windows (GH): "Remove hidden files from removable storages"
CleanAndEject: "Will clean most of the OSX created dot files that pollute every removable drive you plug into your Mac"
CleanMyDrive: "Automatically clean hidden junk from external drives" (now bundled into CleanMyMac)
Hidden Cleaner: Removes macOS 'ghost' files from devices like MP3 players and USB drives before ejecting them, preventing playback errors and compatibility issues
HiM (Hidden Cleaner iMproved): "Cleans and ejects USB devices like MP3 players, USB sticks... (and also local folders)"
USBclean: "Quickly and easily remove pesky junk and ghost files from your external USB drives"
BlueHarvest: "Removes .DS_Store and ._ AppleDouble files from your USB keys, SD cards, music players, file servers or any non Mac disk"
Hidden File Cleaner: "Ensures annoying hidden files don't clutter your drives"
The developer of CleanEject kindly posted a Bash script that does the job admirably (tested in macOS Sequoia):
#!/bin/bash
if [ -d "$1/.Spotlight-V100" ]; then
dot_clean -m "$1"
find "$1" -name .DS_Store -o -name .apdisk -delete
rm -rf "$1/.Trashes"
rm -rf "$1/.Spotlight-V100"
rm -rf "$1/.fseventsd"
rm -rf "$1/.TemporaryItems"
hdiutil unmount "$1"
fi
Here's a slightly modified version that does not require .Spotlight-V100
to be present, fixes .DS_Store
deletion, and uses a safer eject method:
#!/bin/bash
if [ -d "$1" ]; then
dot_clean -m "$1"
find "$1" \( -name .DS_Store -o -name .apdisk \) -type f -delete
rm -rf "$1"/{.Trashes,.Spotlight-V100,.fseventsd,.TemporaryItems}
diskutil eject "$1"
fi
❧ 2025-09-01