A native Swift command-line tool to programmatically enable/disable macOS displays and persist display configurations across system restarts.
- List all connected displays with their IDs and status
- Enable/disable specific displays by ID
- Save display configurations to auto-apply at system startup
- Built-in LaunchAgent installer for automatic configuration restoration
- Safety checks to prevent disabling the last active display
- Configuration persistence via JSON config file
macOS doesn't provide a native way to disable external displays without physically disconnecting them. This tool solves that problem by using Core Graphics Display Configuration APIs to programmatically control display states.
-
Download the latest release:
- Go to Releases
- Download
mac-display-control-vX.X.X.tar.gz
-
Extract and install:
tar -xzf mac-display-control-v1.0.0.tar.gz cd mac-display-control-v1.0.0 chmod +x install.sh ./install.sh -
Configure your displays:
# List displays to get IDs mac-display-control list # Disable the displays you want (use --save to persist) mac-display-control disable <DISPLAY_ID> --save
-
Enable automatic monitoring:
mac-display-control install
Now your display configuration will automatically apply at every login!
See QUICK_START.md for detailed setup instructions.
If you want to build from source instead, see BUILDING.md.
mac-display-control listOutput example:
Connected Displays:
==================
Display 4: Built-in Display [main, built-in]
Status: enabled
Display 5: Dell U2720Q
Status: enabled → will be disabled at startup
Saved Configuration:
-------------------
Displays to disable at startup: 5
Config file: /Users/username/.config/mac-display-control/config.json
The list command shows:
- All connected displays with their IDs
- Current status (enabled/disabled)
- Whether they will be automatically disabled at startup
- Configuration file location (if any displays are configured)
# Temporarily disable display 5
mac-display-control disable 5
# Disable and save configuration (will re-apply at startup)
mac-display-control disable 5 --savemac-display-control enable 5mac-display-control restoreThis applies all saved display configurations (useful for testing before installing the LaunchAgent).
Monitoring Mode (Default - Recommended):
mac-display-control installThis will:
- Create a LaunchAgent plist at
~/Library/LaunchAgents/com.mac-display-control.plist - Load the LaunchAgent using
launchctl - Run a continuous monitoring daemon in the background
The monitoring daemon automatically re-disables displays if macOS re-enables them (e.g., after screen unlock/wake). This ensures your configuration stays active throughout your session.
Restore-Only Mode (Login Only):
mac-display-control install --restore-onlyThis mode only restores your display configuration once at login, without continuous monitoring. macOS may re-enable displays after unlock/wake events.
mac-display-control uninstallThis removes the LaunchAgent and stops automatic configuration restoration.
The tool uses private Core Graphics APIs (CGSConfigureDisplayEnabled) to enable/disable displays. The API is loaded dynamically using dlsym to avoid compile-time linking issues.
Key safety features:
- Prevents disabling the last active display
- Uses atomic display configuration transactions
- Validates display IDs before operations
Display configurations are saved to ~/.config/mac-display-control/config.json:
{
"disabledDisplayIDs": [5, 37038191]
}Monitoring Mode (Default):
The LaunchAgent runs mac-display-control monitor at login, which:
- Applies your saved configuration immediately
- Continues running silently in the background
- Checks every 5 seconds if configured displays are active
- Automatically re-disables them if macOS re-enables them (e.g., after unlock/wake)
- Uses ~0% CPU when idle, minimal memory (~5MB)
Restore-Only Mode:
The LaunchAgent runs mac-display-control restore once at login, then exits.
Plist location: ~/Library/LaunchAgents/com.mac-display-control.plist
Log files:
- stdout:
/tmp/mac-display-control.log - stderr:
/tmp/mac-display-control.error.log
- Disable MacBook built-in display when using external monitors
- Automatically disable specific displays at startup
- Create display profiles for different work setups
- Script display management for automation workflows
This means the private API is not available on your macOS version. The API is available on macOS 10.6+ but may have changed in recent versions.
Check the log files:
cat /tmp/mac-display-control.log
cat /tmp/mac-display-control.error.logVerify the LaunchAgent is loaded:
launchctl list | grep mac-display-controlIf you installed in monitoring mode (default), the daemon automatically re-disables displays within 5 seconds.
If you installed with --restore-only, macOS may re-enable displays after unlock/wake. Solutions:
- Reinstall without
--restore-onlyflag for automatic monitoring - Manually run
mac-display-control restoreafter waking - Create automation using tools like Hammerspoon or BetterTouchTool
-
Core Graphics: Display configuration and enumeration
CGGetActiveDisplayList: List all active displaysCGBeginDisplayConfiguration/CGCompleteDisplayConfiguration: Atomic config changesCGSConfigureDisplayEnabled: Private API to enable/disable displaysCGDisplayIsBuiltin,CGDisplayIsActive, etc.: Display state queries
-
IOKit: Display hardware information
IOServiceMatching: Match display servicesIODisplayCreateInfoDictionary: Get display metadata- Display name extraction from IORegistry
Sources/
├── SimpleMain.swift # CLI interface and commands
├── DisplayControl/
│ └── DisplayManager.swift # Core display control logic
└── Config/
└── ConfigManager.swift # Configuration persistence
- Uses private APIs (may break in future macOS versions)
- Cannot physically power off displays (only tells macOS to not use them)
- Requires user to be logged in (LaunchAgent runs at login, not boot)
- Monitoring mode uses minimal CPU (~0%) but runs continuously in the background
- Tested on: Apple Silicon (M1/M2/M3) running macOS Sequoia
- Intel Macs: Not tested, but should work on macOS 10.15 (Catalina) or later
- Feedback welcome: If you test on Intel or other macOS versions, please report your experience!
This is a utility tool for personal use. Use at your own risk.
Feel free to submit issues or pull requests if you find bugs or have improvements!
Based on research from:
- DisableMonitor by Eun
- disable-monitor by janten
- Various Stack Overflow discussions on macOS display control