6

So I am using Ubuntu and I have encountered many softwares and workarounds for changing wallpapers automatically, BUT, it all pertains to time intervals and what I want is by certain time period.

Like I got this wallpapers for dawn, morning, noon, afternoon, dusk and night. And I want to set my wallpapers that each of them transitions at a certain hour, e.g. 4 am, 8 am, 12 pm, 3 pm, 6 pm and 8 pm. NOT through every 3 hours or so, PLEASE.

I encountered wallch, SyncWall and Variety, but didn't see my intended purpose. Syncwall was close enough, except that it causes a bug with dual monitor wallpapers.

Any other apps/softwares that you could suggest? A manual script would also do, if you may.

Seth
  • 58,122
  • I would believe the following 2 steps: 1. You change the wallpaper with a gsetting, so find out how to do that. 2. add that command to a script and execute that script from /etc/crontab at the given times with a specific wallpaper. – Rinzwind Aug 22 '15 at 09:10
  • I'm sorry @Rinzwind but I'm an amateur when it comes to Linux commands, but I have wide experience in programming. Maybe if you could point out the specific scripts that I should code, that would be great. – anobilisgorse Aug 22 '15 at 10:32

1 Answers1

5
  1. I'm not sure, but maybe you have to install dconf first

    sudo apt-get install dconf-cli
    
  2. Edit your crontab

    crontab -e
    
  3. 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 *)
  4. Save and close your crontab editor

  5. Create the script

    nano change_wallpaper
    
  6. 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 or gsettings. You can switch between both methods. Simply move the # in the front of the gsettings … line to the dconf … line
  7. Make it executable

    chmod +x change_wallpaper
    
  8. 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

  9. 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

steeldriver
  • 136,215
  • 21
  • 243
  • 336
A.B.
  • 90,397
  • The change_wallpaper script for 1 minute worked! I'm just gonna see if the "dusk" would work now, thanks. :) – anobilisgorse Aug 23 '15 at 05:38
  • I was wondering but when I tried installing dconf, it said that E: Package 'dconf' has no installation candidate. But I opted the gsettings anyway. – anobilisgorse Aug 23 '15 at 05:39
  • Sorry, the package is dconf-cli – A.B. Aug 23 '15 at 07:51
  • I just noticed but, if I turned on the PC after 4am, then the scheduled change wallpaper won't take effect. Is there any other way to force the scheduled task? – anobilisgorse Aug 24 '15 at 22:56
  • I have improved my answer. The interval is now every 5 minutes (*/5). The lowest value is 1 minute. And I have added a test in the script to avoid useless changes. – A.B. Aug 25 '15 at 04:45
  • I see, thanks . . . . but may I know what's the interval (1 min ~ 5 mins) for? – anobilisgorse Aug 26 '15 at 06:47
  • The script is started every 5 minutes, and inside the script checks, if the wallpaper should be changed. – A.B. Aug 26 '15 at 07:00
  • Therefore you will see the right wallpaper with a maximum delay of five minutes – A.B. Aug 26 '15 at 07:01
  • Actually, the new script for change_wallpaper didn't worked for me, so I reverted back to the previous one that you gave me. I think that the if statement wasn't that necessary on my PC. – anobilisgorse Aug 28 '15 at 09:14
  • Hey, do you have any ideas with relating to this? http://askubuntu.com/q/739607/442175 It suddenly appeared, but your script worked just fine for about a year. – anobilisgorse Feb 27 '16 at 02:50
  • Hello, your script doesn't seem to work on Ubuntu 16.04 LTS? Any knowledge why? – anobilisgorse Oct 22 '16 at 08:54