Skip to main content

Summary

A cross-platform command line tool that keeps your screen awake using a forward looking relative datetime interface.

On macOS, it uses caffeinate. On Linux, it uses systemd-inhibit.

Install

$ pip install keep-screen-alive

Examples

$ date
Wed Jun  1 08:00:00 CDT 2023

$ keep-alive 2h
Keeping alive until 10:00AM CDT, Jun 01, 2023

$ keep-alive 12pm
Keeping alive until 12:00PM CDT, Jun 01, 2023

$ keep-alive 7am
Keeping alive until 07:00AM CDT, Jun 02, 2023

Configuration

Optional TOML config at $XDG_CONFIG_HOME/keep-alive/config.toml (defaults to ~/.config/keep-alive/config.toml). Override with --config PATH.

Define named aliases that resolve based on time-of-day and weekday. Each alias is an ordered list of rules; the first matching rule wins. Top-level [[rule]] entries are global rules, used as defaults when an alias has no matching rule, and when keep-alive is invoked without arguments.

# global rules: defaults for bare invocation and unmatched aliases
[[rule]]
action = "relative_duration"
duration = "30m"

[[alias]]
name = "work"

    [[alias.rule]]
    start = "05:00"
    end = "16:00"
    days = ["Mon", "Tue", "Wed", "Thu", "Fri"]
    action = "until_window_end"

    [[alias.rule]]
    action = "relative_duration"
    duration = "2h"

[[alias]]
name = "personal"

    [[alias.rule]]
    start = "09:00"
    end = "21:00"
    action = "until_window_end"

    [[alias.rule]]
    action = "relative_duration"
    duration = "1h"

[[alias]]
name = "project"

    [[alias.rule]]
    action = "relative_duration"
    duration = "4h"

keep-alive work on a weekday between 5am and 4pm keeps awake until 4pm; otherwise for 2h. keep-alive personal between 9am and 9pm keeps awake until 9pm; otherwise for 1h. keep-alive project keeps awake for 4h unconditionally. Bare keep-alive uses global rules.

keep-alive --list summarizes the loaded config:

personal
  09:00-21:00 → until 21:00
  always → for 1h
project
  always → for 4h
work
  Mon, Tue, Wed, Thu, Fri 05:00-16:00 → until 16:00
  always → for 2h
global
  always → for 30m

Actions

Kind Required fields Target
relative_duration duration now plus duration
absolute_time time today at HH:MM
until_window_end condition's end today at the window's end
extend_window condition's end, duration window end plus duration

Durations are parsed by dateparser: 2h, 30m, 1h30m, 1d, 45 minutes, etc.

Conditions

Optional. Omit all fields for an unconditional rule (always matches).

  • start, end - time-of-day window as HH:MM. Both must be set to form a range. Start inclusive, end exclusive.
  • days - list of weekday abbreviations: Mon, Tue, Wed, Thu, Fri, Sat, Sun. Omit for daily.

Limitations

  • Overnight windows (e.g. start = "22:00", end = "02:00") aren't supported.

Development

Install Poetry and pre-commit, then:

poetry install
pre-commit install
pre-commit install --hook-type commit-msg

Run tests with poetry run pytest. Pre-commit hooks run ruff (lint and format) on commit; the commit-msg hook verifies conventional commit format; pytest runs as a pre-push hook. CI runs the same checks on pull requests and on push to main.

Commit format

Commits follow Conventional Commits. PR titles must match - they become the squash-merge commit subject. Example: feat: add systemd-inhibit backend. Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert. Subject max 72 chars. Scope optional: fix(backends): handle missing caffeinate.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keep_screen_alive-0.2.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keep_screen_alive-0.2.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file keep_screen_alive-0.2.0.tar.gz.

File metadata

  • Download URL: keep_screen_alive-0.2.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for keep_screen_alive-0.2.0.tar.gz
Algorithm Hash digest
SHA256 dd3c8923939ae6ed75d1dfa3b2d258b00ae6bf40105450d2b51e9c195aa52865
MD5 27cedec23617c79c64f14d19266721aa
BLAKE2b-256 57d9bc6deb2712df3f28e41a1f5380eeda88fdfec52076e55a2781223ef99405

See more details on using hashes here.

Provenance

The following attestation bundles were made for keep_screen_alive-0.2.0.tar.gz:

Publisher: publish.yml on willist/keep-screen-alive

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file keep_screen_alive-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for keep_screen_alive-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c4104d2d15f4066385cf291dc442bfc8423e0169b36dfb0ad3023c9ed5889c2
MD5 0eaf8ea5554da90e90cefb0d5d859021
BLAKE2b-256 cc64bf7c012a6970414c559d736d97a38c42dc53578ca4617dc4badc1702fb8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for keep_screen_alive-0.2.0-py3-none-any.whl:

Publisher: publish.yml on willist/keep-screen-alive

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

This release

0.2.0 This release

2 files

0.1.1

2 files

0.1.0

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page