Skip to content

thairc-dev/mac-server-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

macOS Server Mode (Mac Mini Sleep Preventer)

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).


🌟 Features

  • 🖥️ Menu Bar App: Runs silently in the status menu bar, completely hidden from the Dock (LSUIElement / .accessory mode).
  • 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.

🛠️ Quick Start

1. Build from Source

To compile the Swift application into a native executable:

./build.sh

This generates a compiled binary named mac-server-mode.

2. Run the App

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.

3. Autostart at Login (Recommended for Servers)

To make the application start automatically whenever your Mac Mini starts up and logs in:

./install-launch-agent.sh

🎮 How to Use

  1. Activate Server Mode:

    • Click the 🖥️ Server Idle icon 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.
  2. 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.
  3. Deactivate Server Mode:

    • Click the ⚡ Server Active icon in the Menu Bar and select "Deactivate Server Mode".
    • Or press Ctrl + Option + Cmd + S again.
    • Result: The app returns to 🖥️ Server Idle, and the Mac will resume its normal default sleep behavior.

🗑️ Uninstall

To remove the startup LaunchAgent:

launchctl unload ~/Library/LaunchAgents/com.user.macservermode.plist
rm ~/Library/LaunchAgents/com.user.macservermode.plist
killall mac-server-mode

If you find this tool useful, feel free to support the project via PayPal or by using the Sponsor button on the right. Thank you! ☕


📄 License

MIT License. Feel free to share and modify!

About

Lightweight native macOS Menu Bar app written in Swift to prevent system sleep while keeping the display off. Perfect for Mac Mini home servers.

Topics

Resources

Stars

Watchers

Forks

Releases

Sponsor this project

Packages

Contributors

Languages