wallpaper 947 B

1234567891011121314151617181920212223242526272829
  1. #!/bin/bash
  2. # set sane defaults
  3. [ -z "$wallpaper_sleep_for" ] && wallpaper_sleep_for="180"
  4. [ -z "$wallpaper_path" ] && wallpaper_path="$(xdg-user-dir PICTURES)/wallpaper"
  5. mkdir -p "$wallpaper_path"
  6. # validate wallpaper path
  7. [ $(find "$wallpaper_path" -type f | wc -l) -gt 0 ] || exit 1
  8. # there can be only one
  9. while [ $(ps aux | grep -v 'grep' | grep -c "$0") -gt 2 ]; do
  10. kill $(ps aux | grep -v 'grep' | grep -v $$ | grep "$0" | awk '{print $2}') &> /dev/null
  11. done
  12. # infinitely change wallpaper
  13. while true; do
  14. old_pid=$(ps aux | grep swaybg | awk 'NR==1{ print $2 }')
  15. swaybg_cmd="swaybg"
  16. sway_outputs=( $(swaymsg -t get_outputs | jq -r '.[].name') )
  17. for op in "${sway_outputs[@]}"; do
  18. wp=$(printf '%q' "$(find $wallpaper_path -type f | sort -R | tail -1)")
  19. swaybg_cmd="${swaybg_cmd} -o $op -i $wp -m fit -c \#000000"
  20. done
  21. eval $swaybg_cmd &
  22. sleep 1
  23. [ -n "$old_pid" ] && kill $old_pid 2>/dev/null
  24. sleep $wallpaper_sleep_for
  25. done