Skip to content

Instantly share code, notes, and snippets.

@bigFin
Created December 30, 2024 06:00
Show Gist options
  • Save bigFin/0e49a7de5e338b9c697fb75bddce211d to your computer and use it in GitHub Desktop.
Save bigFin/0e49a7de5e338b9c697fb75bddce211d to your computer and use it in GitHub Desktop.
#!/bin/bash
# Run a random XScreenSaver module in windowed mode
# Path to the XScreenSaver modules
module_path="/usr/lib/xscreensaver"
# Ensure the module path exists
if [ ! -d "$module_path" ]; then
echo "XScreenSaver module path not found: $module_path"
exit 1
fi
# Start the XScreenSaver daemon if it's not running
if ! pgrep -x "xscreensaver" > /dev/null; then
xscreensaver &
sleep 1 # Allow time for the daemon to start
fi
# Extract enabled modules from ~/.xscreensaver and remove "GL:" prefix
modules=$(awk '/^programs:/,/^textMode:/' ~/.xscreensaver | \
grep -v '^-.*--root' | \
grep -- '--root' | \
sed -e 's/^GL: *//' | \
awk '{print $1}')
# Check if any modules are available
if [ -z "$modules" ]; then
echo "No screensaver modules found in the configuration."
exit 1
fi
# Convert the list of modules to an array
IFS=$'\n' read -r -d '' -a module_array <<< "$modules"
# Choose a random module
random_module=${module_array[$RANDOM % ${#module_array[@]}]}
# Run the selected module in windowed mode
if [ -n "$random_module" ]; then
"$module_path/$random_module" -window
else
echo "Failed to select a random screensaver module."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment