I have a bash script (see below) that sets the wallpaper on X11/Waland. This script works fine from the command line.
However, running it from cron gets me the error:
I need either X11 or Wayland, got XDG_SESSION_TYPE="unspecified". WOT?
How do I make it detect that the main user is logged in on a graphical display?
The script:
#!/bin/bash
# Where you top level wallpaper directory is. Note that this work for sub directories too!
WALLPAPER_DIRECTORY=~/Pictures/wallpapers
WALLPAPER=$(find "$WALLPAPER_DIRECTORY" -type f | shuf -n 1)
# X11 code.
if [[ "$XDG_SESSION_TYPE" == "x11" ]]; then
if ! command -v feh &> /dev/null; then
echo "Command feh not found: go install it"
exit 2
fi
/usr/bin/feh --bg-scale "$WALLPAPER"
# Wayland code.
elif [[ "$XDG_SESSION_TYPE" == "wayland" ]]; then
# This requiers https://github.com/JaKooLit/Hyprland-Dots
for cmd in "wallust swww"; do
if ! command -v $cmd &> /dev/null; then
echo "Command $cmd not found: go install it"
exit 2
fi
done
wallust run -q -s "$WALLPAPER" > /dev/null
swww query || swww-daemon && swww img "$WALLPAPER" --transition-type random
$HOME/.config/hypr/scripts/RefreshNoWaybar.sh
# Err… something went catastrophically wrong.
else
echo "I need either X11 or Wayland, got XDG_SESSION_TYPE"=\"${XDG_SESSION_TYPE}\". WOT?""
exit 1
fi