A lightweight, native macOS Menu Bar application written in Swift that allows you to use your Mac (specifically designed for Mac Mini acting as a home/personal server) with the display turned off while ensuring the system stays awake and fully active.
No complex setup, no heavy dependencies, and no Accessibility permissions required (unlike many other shortcut utilities).
- 🖥️ Menu Bar App: Runs silently in the status menu bar, completely hidden from the Dock (
LSUIElement/.accessorymode). - ⚡ Sleep Prevention: Programmatically uses native macOS Power Management assertions (
IOPMAssertionCreateWithName) to prevent the system from going to sleep while active. - 🌙 Instant Display Sleep: Forces the screen to go to sleep immediately using
pmset displaysleepnow. - ⌨️ Global Hotkey (
Ctrl + Option + Cmd + S): Toggle Server Mode at any time, even when the screen is off or another app is focused. Uses Carbon Hotkeys which do not require system Accessibility (Trợ năng) permissions. - 🔄 LaunchAgent Installer: Includes a script to automatically start the application whenever your Mac boots up and you log in.
To compile the Swift application into a native executable:
./build.shThis generates a compiled binary named mac-server-mode.
To start the application in the background:
nohup ./mac-server-mode >/dev/null 2>&1 &You will see a 🖥️ icon in your macOS Menu Bar.
To make the application start automatically whenever your Mac Mini starts up and logs in:
./install-launch-agent.sh-
Activate Server Mode:
- Click the
🖥️ Server Idleicon in your Menu Bar and select "Activate Server Mode". - Or press the global hotkey:
Ctrl + Option + Cmd + S. - Result: The Menu Bar icon changes to
⚡ Server Active, and your screen turns off immediately. Your server applications, SSH, and services will keep running normally.
- Click the
-
Wake Up the Screen:
- Move the mouse or press any key to wake up your display.
- Note: Sleep prevention (Server Mode) remains Active even if the screen wakes up, so your Mac won't go to sleep later.
-
Deactivate Server Mode:
- Click the
⚡ Server Activeicon in the Menu Bar and select "Deactivate Server Mode". - Or press
Ctrl + Option + Cmd + Sagain. - Result: The app returns to
🖥️ Server Idle, and the Mac will resume its normal default sleep behavior.
- Click the
To remove the startup LaunchAgent:
launchctl unload ~/Library/LaunchAgents/com.user.macservermode.plist
rm ~/Library/LaunchAgents/com.user.macservermode.plist
killall mac-server-modeIf you find this tool useful, feel free to support the project via PayPal or by using the Sponsor button on the right. Thank you! ☕
MIT License. Feel free to share and modify!