Automatically change Ubuntu wallpaper at a certain hour
-
I'm not sure, but maybe you have to install
dconf
firstsudo apt-get install dconf-cli
-
Edit your
crontab
crontab -e
-
Add an entry for each background image
*/5 4,5,6,7 * * * /path/to/change_wallpaper '/path/of/your/wallpaper/for/4am' */5 8,8,9,10,11 * * * /path/to/change_wallpaper '/path/of/your/wallpaper/for/8am' */5 12,13,14 * * * /path/to/change_wallpaper '/path/of/your/wallpaper/for/12am' */5 15,16,17 * * * /path/to/change_wallpaper '/path/of/your/wallpaper/for/3pm' */5 18,19 * * * /path/to/change_wallpaper '/path/of/your/wallpaper/for/6pm' */5 20,21,22,23,0,1,2,3 * * * /path/to/change_wallpaper '/path/of/your/wallpaper/for/8pm'
- The interval is set to 5 minutes (
*/5
). - The lowest possible interval is 1 minute (
*/1
or*
)
- The interval is set to 5 minutes (
Save and close your crontab editor
-
Create the script
nano change_wallpaper
-
Add the code below
#!/bin/bash -e user=$(whoami) fl=$(find /proc -maxdepth 2 -user "$user" -name environ -print -quit) for i in {1..5} do fl=$(find /proc -maxdepth 2 -user "$user" -name environ -newer "$fl" -print -quit) done export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS "$fl" | cut -d= -f2-) IMG="file://$1" if [ "$(gsettings get org.gnome.desktop.background picture-uri)" != "$FILE" ]; then dconf write "/org/gnome/desktop/background/picture-uri" "'file://${IMG}'" # gsettings set org.gnome.desktop.background picture-uri "'$IMG'" fi
- The script works with
dconf
orgsettings
. You can switch between both methods. Simply move the#
in the front of thegsettings …
line to thedconf …
line
- The script works with
-
Make it executable
chmod +x change_wallpaper
-
Test the script in your crontab
-
Edit your crontab again
crontab -e
-
Add the (temporary) line below
*/1 * * * * /path/to/change_wallpaper '/path/of/any/wallpaper'
Close the crontab editor
Wait a minute
-
-
If the script works, remove the test entry
-
Edit your crontab again
crontab -e
-
Remove the (temporary) line below
*/1 * * * * /path/to/change_wallpaper '/path/of/any/wallpaper'
Close the crontab editor
-
Script partially taken from here