Prevent system sleep/hibernation while allowing screen lock to engage normally
Go 100%

README.md

awaken #

Prevent system sleep/hibernation while allowing screen lock to engage normally.

Usage #

# Hold inhibitor indefinitely (Ctrl+C to stop)
awaken

# Hold inhibitor for the lifetime of a command
awaken -- make build

# Pass a custom reason (shown in system logs)
awaken --reason "Running database migration" -- ./migrate.sh

# Force a specific backend
awaken --backend systemd-inhibit

# List available backends
awaken --list-backends

# Verbose output
awaken --verbose -- sleep 30

Flags #

Flag Default Description
--reason "awaken: long-running task" Reason passed to the backend's logging/inhibit API
--who "awaken" Identifier for systemd/elogind --who (silently ignored on other backends)
--backend (auto-detect) Force a specific backend: caffeinate, gnome-session-inhibit, kde-inhibit, systemd-inhibit, elogind-inhibit
--list-backends Print detected/available backends in priority order and exit
--verbose Print selected backend and exact command
--version Print version and exit

Supported Backends #

Backend Platform Subprocess Wrap Underlying Mechanism
caffeinate macOS Yes caffeinate -im [-- command]
gnome-session-inhibit Linux (GNOME) Yes gnome-session-inhibit --inhibit suspend:idle
kde-inhibit Linux (KDE) Yes kde-inhibit --power
systemd-inhibit Linux (systemd) Yes systemd-inhibit --what=sleep --mode=block
elogind-inhibit Linux (elogind) Yes elogind-inhibit --what=sleep --mode=block

Detection order (Linux) #

  1. gnome-session-inhibit — if $XDG_CURRENT_DESKTOP contains "GNOME", or if gnome-session-inhibit is in $PATH and a GNOME session is running
  2. kde-inhibit — if $XDG_CURRENT_DESKTOP contains "KDE", or if kde-inhibit is in $PATH
  3. systemd-inhibit — if systemd-inhibit is in $PATH
  4. elogind-inhibit — if elogind-inhibit is in $PATH

Install #

go install dario.cat/awaken@latest

Or clone and build:

git clone https://dario.cat/awaken.git
cd awaken
go build -o awaken .

How it works #

awaken wraps platform-specific inhibitor tools through a common interface. On macOS it uses caffeinate -im (never -d, so the screen can still lock). On Linux it auto-detects the desktop environment or init system and uses the appropriate inhibitor.

When a command is provided after --, awaken holds the inhibitor only for the lifetime of that subprocess and exits with the same exit code. Without a command, it holds indefinitely until interrupted (SIGINT/SIGTERM).

Signals (SIGINT/SIGTERM) are forwarded to the child process when one is running.

Requirements #

  • Go 1.26+
  • macOS: caffeinate (built-in)
  • Linux: one of gnome-session-inhibit, kde-inhibit, systemd-inhibit, or elogind-inhibit