Advertisement
Arafat_H_Rakib

Nitrogenium wallpaper randomizer

Dec 28th, 2018
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.80 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ## Nitrogenium is a wallpaper randomizer for Openbox based on Nitrogen
  4. ## this script was inspired by but is *NOT* based on Variety by Peter Levi
  5.  
  6. ## requires: nitrogen, imagemagick, notify-send
  7.  
  8. # some settings
  9. MINCOUNT=5              # don't make smaller than two
  10. CONFIG=/home/$USER/.config
  11.  
  12. # get path of current wallpaper from bg-saved.cfg
  13. CURRENT=`grep -Po "(?<=file=).*" "$CONFIG/nitrogen/bg-saved.cfg"`
  14. #read the wallpaper directories from nitrogen.cfg
  15. FILES=`grep -Po "(?<=dirs=).*" "$CONFIG/nitrogen/nitrogen.cfg" | sed "s/;/\/\* /g"`
  16.  
  17. # make sure there are enough wallpapers available, randomizing doesn't make a lot of sense with only a few wallies.
  18. COUNT=`ls $FILES | grep -Eic ".*\.(png|jpe?g|bmp)"`
  19. if [ $COUNT -ge $MINCOUNT ]; then
  20.     # pick a random wallpaper from these directories and make sure it's different from the current wallpaper
  21.     NEW=`ls $FILES | grep -Ei ".*\.(png|jpe?g|bmp)" | shuf -n 1`
  22.     while [ "$NEW" = "$CURRENT" ]; do
  23.         NEW=`ls $FILES | grep -Ei ".*\.(png|jpe?g|bmp)" | shuf -n 1`
  24.     done
  25.  
  26.     # create thumbnail for notification bubble
  27.     convert "$NEW" -thumbnail 50x50^ -gravity Center -crop 50x50-0-0 "$CONFIG/openbox/thumb.png"
  28.     # extract filename from path for notification bubble
  29.     NAME=`echo $NEW | grep -Pio "[^/]*(?=\.(png|jpe?g|bmp))" | cut -c1-100`
  30.     # set the wallpaper with nitrogen and notify user
  31.     nitrogen --set-scaled $NEW && { notify-send -t 5000 -i "$CONFIG/openbox/thumb.png" "Nitrogenium" "Changed wallaper to \"$NAME\""; sed -i "s!^file=.*!file=$NEW!" $CONFIG/nitrogen/bg-saved.cfg; }
  32.  
  33.     # remove thumbnail
  34.     rm -f "$CONFIG/openbox/thumb.png"
  35. else
  36.     # notify user that there are not enough wallpapers available
  37.     notify-send -t 1000 -i error  "Nitrogenium" "Not enough wallpapers for random changing"
  38. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement