Skip to content

SupaOhm/NoSleep-CLI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

NoSleep CLI

NoSleep CLI is a lightweight Windows command-line utility that prevents the system from entering sleep mode or turning off the display.

The tool signals activity directly to the Windows kernel, meaning it does not modify power plans or registry settings and restores normal behavior immediately when stopped.

Features

  • Keep Awake: Prevents system sleep and display power-off.
  • Background Support: Execution tracking using a PID file.
  • Timer Mode: Run for a specific duration (seconds, minutes, or hours).
  • Clean Management: Dedicated start, stop, and status commands.
  • User-Friendly: No administrator privileges required.

Supported Platform

  • Windows 10 or later
  • Uses the Win32 API function: SetThreadExecutionState

Installation

Prerequisites

Install from Source

git clone https://github.com/SupaOhm/NoSleep-CLI.git
cd NoSleep-CLI
py -m pip install .

or Download NoSleep

Windows PATH Configuration (Required)

If you see a warning that nosleep.exe is installed in a directory not on PATH, follow these steps:

  • Press Win + R, type sysdm.cpl, and press Enter.
  • Open AdvancedEnvironment Variables.
  • Under User variables, select PathEdit.
  • Click New and add the path provided in the warning (e.g., C:\Users\<your-username>\AppData\Local\Programs\Python\Python314\Scripts).
  • Click OK on all dialogs and restart your terminal.

Usage

  • After installation, you can use the nosleep command in your terminal.
  • For help and usage instructions, run:
nosleep --help

Basic Commands

Command Description

  • nosleep Starts NoSleep in the foreground. Prevents sleep until Ctrl+C.
  • nosleep stop Terminates the running NoSleep process and removes the PID file.
  • nosleep --status Checks if a NoSleep process is currently active.
  • nosleep --timer <duration> Runs NoSleep for a specified duration (e.g., 30m for 30 minutes).

Time Examples

  • Run NoSleep for a fixed duration, after which it will stop automatically.
  • Supported units: s (seconds), m (minutes), h (hours).
nosleep --timer 30m   # Stay awake for 30 minutes
nosleep --timer 2h    # Stay awake for 2 hours
nosleep --timer 90s   # Stay awake for 90 seconds

How It Works

  • Win32 API Integration
  • The tool utilizes ctypes to call SetThreadExecutionState with the following flags:
  • ES_SYSTEM_REQUIRED: Forces the system to be in the working state.
  • ES_DISPLAY_REQUIRED: Forces the display to be on.
  • ES_CONTINUOUS: Informs Windows the state should persist until the next call or the thread ends.

Process Management

  • To handle tracking and safe shutdowns, NoSleep stores a PID file at: %USERPROFILE%\.nosleep.pid
  • This enables background tracking and ensures that the stop command can find and terminate the specific process correctly.

Uninstall

To remove NoSleep CLI:

py -m pip uninstall NoSleep-CLI

Limitations

  • Windows-only: Relies on specific Win32 API calls.
  • Terminal Window: The terminal must remain open while running in foreground mode.
  • Hard Overrides: Does not override forced hardware shutdowns or critical battery events.

Roadmap

  • Background daemon mode (fully detached from terminal)
  • Scheduled execution support
  • Windows Service implementation
  • Standalone .exe distribution (via PyInstaller)

About

A lightweight Windows command-line utility that prevents the system from entering sleep mode or turning off the display cuz my PC always did.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages