Small script for setting a random Reddit wallpaper on Openbox
Recently I tuned my computer at work, and set Openbox as my desktop environment, which is my favorite Linux desktop environment, with my usual key bindings, configuration files and so.
For setting a wallpaper I wasn't sure which one could I choose so I created this small bash script for setting a random wallpaper using Reddit as the source every time I start the PC.
#!/bin/bash
rm ~/wallpaper.jpg
subreddits=("EarthPorn" "Wallpaper" "Wallpapers" "CityPorn" "SkyPorn" "BeachPorn" "SpacePorn" "WaterPorn")
subreddit=${subreddits[$RANDOM % ${#subreddits[@]}]}
ID="$(wget -q "https://imgur.com/r/$subreddit" -O - | grep '"post"' | grep class | cut -d\" -f 2 | head -1)"
echo "Downloading $ID.jpg"
wget -c -q -N "https://i.imgur.com/$ID.jpg" -O ~/wallpaper.jpg
feh --bg-fill ~/wallpaper.jpg
This script will get an image from reddit using wget
and will save it into your home folder, then using feh
will set it as the wallpaper.I included a list of subreddits containing images suitable for having nice wallpapers like SpacePorn
, EarthPorn
or Wallpaper
Then save the script in your home folder as wallpaper.sh, set it to executable using chmod
and add the execution of this script to the startup of openbox adding the following line to ~/.config/openbox/autostart
:
sh ~/wallpaper.sh