Automatically take screenshots at a random time every hour. Wayland only,
using grim.
What you can change:
- frequency:
OnCalendarvalue insystemd-service/autoscreen.timer - directory from where autoscreen will be run:
WorkingDirectoryvalue insystemd-service/autoscreen.service - directory where the screenshots will be stored:
DESTINATION_DIRvariable inautoscreen.sh(overridable at runtime with theAUTOSCREEN_DESTINATION_DIRenvironment variable) - file name suffix:
AUTOSCREEN_FILENAME_SUFFIXenvironment variable, inserted just beforeautoscreen.png(useful to tell machines/installations apart) - output format:
AUTOSCREEN_FORMATenvironment variable —png(default),jpeg,ppm,webp,aviforjxl - encoder quality:
AUTOSCREEN_QUALITYenvironment variable,0-100(default90, higher is better; ignored forpng/ppm)
grim- for
webp/avif/jxloutput:cwebp(libwebp),avifenc(libavif),cjxl(libjxl) respectively
git clone https://github.com/dbeley/autoscreen
cd autoscreen
chmod +x autoscreen.sh
cp systemd-service/* ~/.config/systemd/user
systemctl --user daemon-reload
systemctl --user enable --now autoscreen.timer
systemctl --user status autoscreen
A flake is provided, exposing the package, an overlay and a Home Manager module.
Try it without installing:
nix run github:dbeley/autoscreen
Add the flake as an input:
# flake.nix
inputs.autoscreen.url = "github:dbeley/autoscreen";Then import the module and enable the service:
{
imports = [ inputs.autoscreen.homeModules.default ];
services.autoscreen = {
enable = true;
# destinationDir = "%h/Nextcloud/07_Images/01_autoscreen";
# filenameSuffix = "nixos_";
# format = "png"; # png | jpeg | ppm | webp | avif | jxl
# quality = 90; # 0-100, higher is better (ignored for png/ppm)
# onCalendar = "hourly";
# randomizedDelaySec = 3600;
};
}Note: destinationDir uses the systemd %h specifier for the user's home
directory instead of $HOME (systemd expands %h in Environment=, not $HOME).
A PNG of a 4K screenshot is large (several MB, more on detailed content such as games). The lossy formats are roughly an order of magnitude smaller:
| format | relative size (4K content) | notes |
|---|---|---|
png |
100 % (baseline) | lossless, grim-native |
jxl |
~8–10 % | best perceived quality, grim cannot emit it |
avif |
~5–10 % | smallest, but visible artifacts on fine texture |
webp |
~10–40 % | broadest viewer support |
jpeg |
~9 % on photos, >100 % on flat UI | grim-native, but poor for screenshots |
quality is passed straight to the encoder (grim -q, cwebp -q, avifenc
-q, cjxl -q), so it means the same thing everywhere: higher is better,
100 is lossless for avif and jxl.
# packages
nix build github:dbeley/autoscreen
# overlay
{
inputs.autoscreen.url = "github:dbeley/autoscreen";
nixpkgs.overlays = [ inputs.autoscreen.overlays.default ];
# pkgs.autoscreen is then available
}