It’s 7:30 PM, my usual time for weekly maintenance across all my machines. That includes software updates, app patches, clearing out cruft, and making sure everything runs like clockwork. I block time for this regularly, not just for my laptops and desktops, but also for phones, gadgets, and even vehicles. Part of owning things is taking care of them so they won’t fail when you need them most.
As I was wrapping up, something caught my eye. Both my macOS and Windows machines have some form of dynamic wallpaper. They change based on time or conditions. Meanwhile, my Linux box? Still rocking the same static background since forever. That was the moment I paused and asked myself:
“Why not build it myself?”
I could’ve fired up Cursor and let AI take over, but I decided to go full manual. Opened up VSCode and got my hands dirty. While I’m fluent in Python, Go, and the usual suspects, Bash scripting is more of a sidekick for me, usually just to chain 2–5 commands. But this time, I dove deeper.
Long story short, after 4–5 hours of tinkering, trial and error, and a few dead ends, I ended up building a script that works. And it feels good to be a beginner again, solving something from scratch, Googling silly things, and hitting that moment where it finally clicks.
So, what does it do?
The script checks your system’s current time and decides which wallpaper “session” to use. I split the day into 4 sessions:
- Sunrise (05:00 to 09:00)
- Noon (09:00 to 16:00)
- Sunset (16:00 to 19:00)
- Night (19:00 to 05:00)
Each session has its own wallpaper folder with 10 images. The script randomly picks one and sets it as your wallpaper.
Simple idea, clean execution.
But here’s where it got interesting…
I automated the script using cron, set to run every minute. Sounds great, right? Not really. Two unexpected issues showed up:
-
It changed wallpapers every single minute. Super annoying.
✅ Fix: I added a check. If the current wallpaper is already from the correct session, just skip it. -
Cron is headless and has no access to the GUI.
✅ Fix: I passed in the necessary environment variables likeDISPLAY=:0andDBUS_SESSION_BUS_ADDRESSso the script could talk to GNOME’s settings properly. Thanks, StackOverflow.
Once it worked, I finally launched Cursor, refactored the code with AI help, cleaned it up, added comments, and even auto-generated a README.md to make it easier for others to use.
It’s live.
The source code is here:
👉
https://github.com/ksetyadi/gnome-auto-wallpaper
Feel free to clone, use, tweak, or fork it however you like. If it works on your machine, even better. That would beat the classic “it works on my machine” meme. 😄
UPDATE: I also put an auto-changing theme between default (light) and prefer-dark (dark) along with the auto-changing wallpaper.
UPDATE 2: Some people asked me to change the variables (sessions in a day) to a configuration file so it’s easier to change without breaking the main script. I’ve updated the script to read from configuration file (auto.conf) so you just have to change it instead of changing the auto.sh file.