Script output over a random image in swaylock

Nothing really sophisticated, but looks not bad. Maybe some sway / river / dwl / whatever user finds it useful.

  1. Prerequisites: swaylock, nwg-wrapper

  2. Save this to your bin folder, make executable, run to lock the screen:

#!/bin/bash

nwg-wrapper -s swaylock-time.sh -o eDP-1 -r 20000 -c timezones.css -p right -mr 50 -a start -mt 0 -j right -l 3 -sq 31 &

pic=$(rffd -p /home/piotr/Obrazy/lockscreen/)
sleep 0.5 && swaylock --image $pic && pkill -f -31 nwg-wrapper

  1. The script to produce whatever content displayed by nwg-wrapper over swaylock. Save as ~/.config/nwg-wrapper/swaylock-time.sh, make executable. Use own path to images folder:
#!/bin/bash

time=$(date +'%a, %d. %b  %H:%M')
echo '<span size="20000" foreground="#c6ad8f" face="monospace">'$time'</span>'
echo; echo '<span size="12000" foreground="#cccccc" face="monospace">'$(echo $USER)'@'$(uname -n) on $(uname -sr)'</span>'
echo '<span size="12000" foreground="#cccccc" face="monospace">'$(uptime -p)'</span>'
  1. Simple ~/.config/nwg-wrapper/timezones.css contains nothing but a transparent window:
window {
    background-color: rgba (0, 0, 0, 0.0);
}
  1. Python script to draw a random image. Save as rffd in your bin directory, make executable:
#!/usr/bin/python3

"""
This scripts returns a random file path from given directory.
Subdirectories are not being searched.
"""

import os
import argparse
import sys
import random


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-p",
                        "--path",
                        type=str,
                        default="",
                        help="full path to draw the file from")

    args = parser.parse_args()
    if not args.path:
        print("No patch specified")
        sys.exit(1)

    if not os.path.isdir(args.path):
        print("{} is not a directory".format(args.path))
        sys.exit(1)
    else:
        files = []
        paths = os.listdir(args.path)
        for p in paths:
            if os.path.isfile(os.path.join(args.path, p)):
                files.append(p)

        print(os.path.join(args.path, files[random.randint(0, len(files)-1)]))


if __name__ == '__main__':
    main()

5 Likes

Top job again @nwg

Nice video !

1 Like

Cool idea @nwg, thanks for the share!!

1 Like