A macOS command-line utility for switching default file associations by file extension.
macdefault changes the default app for any file extension using macOS LaunchServices and duti. It also includes preset switches for common office suites.
What it does:
- Pick a default app for any extension interactively (
--ext=mp3). - Switch office presets in one command (
--microsoft,--wps,--apple). - Show current defaults and installed bundle IDs for troubleshooting.
Preset extensions (suite mode):
doc,docx,xls,xlsx,ppt,pptx,rtf,csv
- macOS
- Python 3.10+
- duti (
brew install duti)
brew install duti
uv tool install macdefault
macdefault --helppython -m pip install macdefault
macdefault --helpgit clone https://github.com/ac1982/macdefault.git
cd macdefault
uv sync
uv run macdefault --helpChoose a default app for a specific extension:
macdefault --ext=mp3Show candidates without making changes:
macdefault --ext=mp3 --showInteractive selection:
- Up/Down arrows to move
- Enter to confirm
- 1-9 to quick select
- q to cancel
Switch all preset extensions to Microsoft Office:
macdefault --microsoft
# or
macdefault --officeSwitch to WPS Office:
macdefault --wps
# or
macdefault --kingsoftSwitch to Apple iWork:
macdefault --applePrint a summary of installed suites:
macdefault --print-bundle-idsFull diagnostic output (bundle IDs + current defaults):
macdefault --doctorDry run (preview changes without applying):
macdefault --microsoft --dry-runDisable verification (skip checking if changes succeeded):
macdefault --wps --no-verifyFail fast (stop on first error):
macdefault --apple --fail-fast- Discovery: scans common application directories (
/Applications, etc.) - UTI matching: uses macOS Uniform Type Identifiers to find apps that support each extension
- LaunchServices: registers apps with
lsregisterwhen needed - duti: applies defaults via
duti -s <bundle-id> <extension> all - Verification: checks that changes were applied correctly
- WPS Office: uses a stable path (
/Applications/wpsoffice.app) since LaunchServices name lookup can be unreliable - Microsoft Word
.doc: includes repair logic if the default does not stick
"duti not found"
- Install via:
brew install duti
"Microsoft Office apps not fully resolvable"
- Ensure Word, Excel, and PowerPoint are installed in
/Applications - Try running
macdefault --print-bundle-idsto see what is detected
Changes do not stick for .doc
- The script re-registers Word with LaunchServices and tries multiple UTI identifiers
App not appearing in --ext list
- The app must declare support for that file type in its Info.plist
- Workaround: Finder right-click file -> Open With -> Other -> Change All
macdefault/
├── macdefault.py # Main script
├── pyproject.toml # Project metadata and dependencies
├── README.md # This file
├── .python-version # Python version specification
└── .gitignore # Git ignore rules
# Add tests in the future
uv run pytest# Add formatters as dev dependencies if needed
uv add --dev ruff black
uv run black macdefault.py
uv run ruff check macdefault.py- Uses
mdlsfor fast metadata queries when available - Falls back to parsing
Info.plistdirectly - Filters out overly-generic UTIs (
public.data,public.item,public.content) - Supports wide Unicode characters in table output via
wcwidth - Interactive mode supports q to cancel
MIT License - See LICENSE file for details.