Ask Dave Taylor
  • Facebook
  • Instagram
  • Linkedin
  • Pinterest
  • Twitter
  • YouTube
  • Home
  • YouTube Videos
  • Top Categories
  • Subscribe via Email
  • Ask A Question
  • Meet Dave
  • Home
  • Linux Help
  • Change Ubuntu Linux Backgrounds Based on Light/Dark Theme?

Change Ubuntu Linux Backgrounds Based on Light/Dark Theme?

December 15, 2022 / Dave Taylor / Linux Help, Linux Shell Script Programming / No Comments

I noticed the other day that one of the Ubuntu Linux systems in our IT center changes theme at sunset and that the background wallpaper changes, not just the window colors. Nice. How can I do that on my own computer?

While light and dark themes have become the standard for most modern operating systems, automating when that switch happens is far less standardized. The best systems offer you a single click to enable having your computer change to dark mode at sunset and back to light mode at sunrise, but while Ubuntu and its GNOME graphical interface offer light and dark themes, there’s not yet any automation for switching.

This means that the IT center has cobbled something together and the easiest solution might be to ask one of them to help you emulate it on your own computer. There’s an extension you can install, but it’s somewhat convoluted because it requires installing some helper utilities beforehand. You can also manage it all through a shell script or two, which I’ll show, but automating that requires you to create cron jobs which is also a bit tricky.

To start, though, let’s look at how GNOME automatically does offer different backgrounds for light and dark themes.

GNOME & LINUX: BACKGROUND BASED ON THEME

On my Ubuntu Linux system running GNOME I have the following background wallpaper, as detailed in the Settings app:

ubuntu linux gnome wallpaper background theme - light image

Look closely at the text under the image here in Settings > Background and you’ll see it says “This background selection only applies to the light style.”

A click on Settings > Appearance shows the light/dark theme switch (without, alas, any scheduling or automation):

ubuntu linux gnome wallpaper background theme - settings appearance

If I switch to “Dark” style (theme, mode, everyone has a different name for it!) then the background image automatically changes…

ubuntu linux gnome wallpaper background theme - dark theme photo

Switch back to Settings > Background and I can change this Dark style background image, knowing it will only be used when I have selected Dark mode:

ubuntu linux gnome wallpaper background theme -

To change it to something else suitable, I’ll find an image that is primarily dark – to stick with the theme – and click. It instantly changes what’s on the main screen too:

ubuntu linux gnome wallpaper background theme - new wallpaper

If you want the light and dark themes to have the same background wallpaper, you can now switch style, chose the image you desire, and know it’s all set.

AUTOMATING THE LIGHT/DARK THEME SWITCH?

The wrinkle is when you decide you’d like to have this light/dark switch automated. One possibility that’s elegant once you get it properly installed is Night Theme Switcher, which unfortunately doesn’t support Ubuntu GNOME, so if that’s the distro you’re running, it’s not going to work.

Instead, it’s time to utilize the command line. Yes, open up that Terminal and let’s get typing!

To find out the current state of your Desktop theme, uh, style, use this command:

$ gsettings get org.gnome.desktop.interface color-scheme
prefer-dark
$

That shows that the current setting is “prefer-dark”. To switch it to Light, use “set” instead of “get” and specify that you’d, well, prefer light:

$ gsettings set org.gnome.desktop.interface color-scheme prefer-light
$

Note in these examples you only need to type in the bold characters, not the “$” symbol, which is just a prompt.

With this setup, you can easily then create aliases for ‘light’ and ‘dark’ that you can type in to switch to the specified theme:

$ alias light="gsettings set org.gnome.desktop.interface color-scheme prefer-light"
$ alias dark="gsettings set org.gnome.desktop.interface color-scheme prefer-dark"

Drop those into your ~/.login file or equivalent to have them available the next time you log in too. Now you can switch by just typing “dark” or “light”. Turn this into a shell script and you can have “switch” which switches from the current mode to the other so you don’t have to remember (by utilizing both comments shown above):

#!/bin/sh

# switch.sh - switch light/dark theme in GNOME on Ubuntu Linux

# 1. get current state:

scheme="$(gsettings get org.gnome.desktop.interface color-scheme)"

# 2. switch state:

if [ "$scheme" = "'prefer-light'" ] ; then
   newscheme="prefer-dark"
else
   newscheme="prefer-light"
fi

echo Switching theme to $newscheme

gsettings set org.gnome.desktop.interface color-scheme $newscheme

exit 0

With this new script you can automate the process through a cron job, which you can learn more about with ‘man cron’ (or ask your administrator or IT team for assistance).

That’ll get you going with your own solution and you picked up a bit of command line expertise too. Well done!

Pro Tip: I’ve been writing about Linux since the dawn of the operating system, and Unix before that. Please check out my extensive Linux help area and Linux shell script programming area for lots of additional tutorial content while you’re visiting. Thanks!

About the Author: Dave Taylor has been involved with the online world since the early days of the Internet. Author of over 20 technical books, he runs the popular AskDaveTaylor.com tech help site. You can also find his gadget reviews on YouTube and chat with him on Twitter as @DaveTaylor.

Let’s Stay In Touch!

Never miss a single article, review or tutorial here on AskDaveTaylor, sign up for my fun weekly newsletter!
Name: 
Your email address:*
Please enter all required fields
Correct invalid entries
No spam, ever. Promise. Powered by FeedBlitz
Please choose a color:
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!
linux gnome light theme, linux shell scripting, switch gnome themes

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Recent Posts

  • How Can I Stop Sharing my Xfinity Internet Connection via xfinitywifi?
  • Guide to Identifying and Blocking Off-Facebook Data Tracking
  • How Can I Share My Netflix Account With My Friend? [Updated for 2023]
  • How to Check Energy Recommendations on your Windows Laptop
  • How Do I Customize New Tab Windows in Safari for Mac?

On Our YouTube Channel

Audeze FILTER Bluetooth Conference Speakerphone -- DEMO & REVIEW

How to: Replace a Switchbot Door Sensor Battery

Categories

  • AdSense, AdWords, and PPC Help (106)
  • Amazon, eBay, and Online Shopping Help (163)
  • Android Help (226)
  • Apple iPad Help (147)
  • Apple Watch Help (53)
  • Articles, Tutorials, and Reviews (346)
  • Auto Tech Help (15)
  • Business Advice (200)
  • ChromeOS Help (31)
  • Computer & Internet Basics (780)
  • d) None of the Above (166)
  • Facebook Help (384)
  • Google, Chrome & Gmail Help (188)
  • HTML & Web Page Design (247)
  • Instagram Help (49)
  • iPhone & iOS Help (623)
  • iPod & MP3 Player Help (173)
  • Kindle & Nook Help (99)
  • LinkedIn Help (88)
  • Linux Help (173)
  • Linux Shell Script Programming (89)
  • Mac & MacOS Help (911)
  • Most Popular (16)
  • Outlook & Office 365 Help (33)
  • PayPal Help (68)
  • Pinterest Help (54)
  • Reddit Help (19)
  • SEO & Marketing (82)
  • Spam, Scams & Security (95)
  • Trade Show News & Updates (23)
  • Twitter Help (220)
  • Video Game Tips (66)
  • Web Site Traffic Tips (62)
  • Windows PC Help (947)
  • Wordpress Help (206)
  • Writing and Publishing (72)
  • YouTube Help (47)
  • YouTube Video Reviews (159)
  • Zoom, Skype & Video Chat Help (62)

Archives

Social Connections:

Ask Dave Taylor


Follow Me on Pinterest
Follow me on Twitter
Follow me on LinkedIn
Follow me on Instagram


AskDaveTaylor on Facebook



microsoft insider mvp


This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to our terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. Our lawyer says "Thanks for your cooperation."
© 2023 by Dave Taylor. "Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.
Privacy Policy - Terms and Conditions - Accessibility Policy