A cross-platform system sleep utility supporting Windows, macOS, and Linux with both CLI and GUI interfaces.
- CLI Scripts: Command-line tools for scheduling system sleep with configurable delays
- GUI Applications: Visual interfaces with countdown timers and progress bars
- Sleep Prevention: Prevent system from sleeping while performing important tasks
- Multi-Cycle Support: Automatically resume sleep cycles after system wakes
- Configuration Management: Centralized config file with CLI overrides
- Comprehensive Logging: Track all sleep operations with timestamps
| Platform | Status | Interface | Notes |
|---|---|---|---|
| Windows 10/11 | ✅ Supported | CLI + GUI | Uses Rundll32.exe Powrprof.dll,SetSuspendState |
| macOS | ✅ Supported | CLI | Uses caffeinate for sleep prevention |
| Linux (systemd) | ✅ Supported | CLI + GUI | Fedora, Ubuntu, Debian, Arch, openSUSE, RHEL |
- Python 3.10+
- Windows: Admin privileges recommended, hibernation enabled
- Linux: Systemd-based distribution
- All platforms: Built-in Python modules only (no external dependencies except optional
requestsfor macOS)
# Clone or download the repository
cd systemSleep
# No additional dependencies required for Windows/Linux
# For macOS with exchange rate monitoring:
pip install requests# Interactive mode
python windows_sleep.py
# With command-line arguments
python windows_sleep.py --delay 10 --wake-delay 3 --timeout 20 --log-file sleep.log
# Silent immediate sleep (rename to .pyw and double-click)
python windows_sleep.pyw
# Show help
python windows_sleep.py --helppython windows_sleep_gui.pywWindows Setup:
# Enable hibernation (required for full functionality)
powercfg -h on# Monitor USD→INR exchange rates while preventing system sleep
python macos_prevent_sleep.py
# With custom settings
python macos_prevent_sleep.py --api-url "https://your-api.com" --interval 120
# Show help
python macos_prevent_sleep.py --help# Interactive sleep mode
python linux_sleep.py
# Sleep with arguments
python linux_sleep.py --mode sleep --sleep-type suspend --delay 10
# Prevent system sleep
python linux_sleep.py --mode prevent --prevent-reason "Long download"
# Show help
python linux_sleep.py --help# Modern GUI with mode selector and settings
python linux_sleep_gui.pywLinux Setup (Optional - for non-root sleep without password):
Create /etc/polkit-1/rules.d/85-suspend.rules:
sudo nano /etc/polkit-1/rules.d/85-suspend.rulesAdd the following content:
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.login1.suspend" ||
action.id == "org.freedesktop.login1.hibernate" ||
action.id == "org.freedesktop.login1.hybrid-sleep") {
if (subject.isInGroup("wheel")) {
return polkit.Result.YES;
}
}
});Then restart polkit:
sudo systemctl restart polkitAll scripts load settings from config.json with the following priority:
- Command-line arguments (CLI scripts only)
- Values from
config.json - Hardcoded defaults
{
"linux_sleep": {
"log_file": "linux_sleep.log",
"sleep_command_timeout": 15,
"wake_delay_minutes": 5,
"default_delay_minutes": 0,
"default_sleep_type": "suspend"
},
"linux_sleep_gui": {
"enable_cycling": true,
"default_sleep_type": "suspend"
}
}- windows_sleep.py - Windows CLI sleep scheduler
- windows_sleep_gui.pyw - Windows GUI with settings and timer
- macos_prevent_sleep.py - macOS exchange rate monitor with sleep prevention
- linux_sleep.py - Linux CLI sleep/prevention scheduler
- linux_sleep_gui.pyw - Linux modern GUI
- linux_sleep_helpers.py - Shared Linux utilities
- config_loader.py - Configuration management
- config.json - Configuration file
- Sleep Command:
Rundll32.exe Powrprof.dll,SetSuspendState Sleep - Hibernation: Must be enabled with
powercfg -h on - Logging: File-based logging to
sleep.log - Multi-Cycle: 5-minute wait after wake-up before next sleep
- Sleep Prevention: Uses
caffeinate -isubprocess - Exchange Rate API: Fetches USD→INR rates from
https://open.er-api.com/v6/latest/USD - Dependencies: Requires
requestsmodule - Signal Handling: Graceful Ctrl+C shutdown
- Sleep Types: Suspend (RAM), Hibernate (disk), Hybrid-sleep (both)
- Sleep Command:
systemctl suspend|hibernate|hybrid-sleep - Sleep Prevention:
systemd-inhibit --what=sleep - Permission Check: Uses
systemctl --dry-runto verify permissions - Logging: File-based logging to
linux_sleep.log - Supported Distributions: Fedora, RHEL, Ubuntu, Debian, Arch, openSUSE (any systemd-based)
Check operation logs for debugging and monitoring:
# Windows
cat sleep.log
tail -f sleep.log
# Linux
cat linux_sleep.log
tail -f linux_sleep.log- "Admin rights required": Run Command Prompt or PowerShell as Administrator
- "Hibernation not enabled": Execute
powercfg -h onin PowerShell - Sleep command times out: Check if system is unresponsive
- "Systemd not detected": Ensure you're running a systemd-based distribution
- Permission denied: Run with sudo or configure polkit rules (see setup above)
- "systemd-inhibit not found": Install systemd package (
sudo dnf install systemdon Fedora)
- "requests module not found": Install with
pip install requests - Exchange rate fetch fails: Check internet connection, API may be temporarily unavailable
All scripts follow consistent patterns:
- Platform Detection: Scripts check their target platform and exit gracefully on others
- Error Handling: Subprocess timeouts, permission errors, and network failures handled appropriately
- Logging: All operations logged with timestamps for debugging
- Configuration: Three-tier priority system (CLI args > config > defaults)
- Threading: GUI applications use daemon threads for non-blocking operations
For detailed architecture notes, see CLAUDE.md.
See LICENSE file for details.
Improvements and cross-platform enhancements welcome!