Food for thought - Is this possible?

Ok, so over the last couple of nights I’ve been having a thought. Could I use the “cron jobs” command to set a specific time, to change my wallpaper, and then back again at another time? I’m asking because, usually at night when I goto bed I leave my laptop on and because the display comes through on the external monitor, I get blinded by the bright light from the wallpaper.

Now you could say, “well turn your monitor off then.” I would, but I use it as a clock so I can see what time it is when I wake up, wouldn’t be a very handy clock if it was blank now would it? You could also say: “Well change the wallpaper then,” I would but I don’t feel like navigating through my NAS’s folder in order to pick from some 300+ wallpapers.

I know there are GUI programs out there that will change the background, but I want to do it at a specific time, like a timer on a boiler’s programmer for instance. The reason I ask if cronjobs will do it is because, it’s already on the system and it’s function is to do jobs somewhat like I’m looking to do. I don’t want to be downloading software because I am now running quite low on disk-space due to Win8 being a fat pig on another partition.

Interesting food for thought, perhaps someone can answer. I think perhaps using a bash script or something like that may be the way to go.

Of course you can … this is Linux :wink: … just depends how much effort you’re willing to put it.

I’d also suggest you’re on the right track … write (or find and edit) a script … run it with cron.

Do you use cron for anything at the moment?

You are right in thinking about using cron, it is a task scheduler after all.

I use cron to start and stop programs without my input,I’v never used it to alter settings though. That doesn’t mean it’s not possible.

As Mark says you could try and find one which you could edit to meet your own requirments. I’ll have a play around to see how far I can get.

Not at the moment, no.

I have come across a script for changing the wallpaper:

Crontab:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@hourly /share/scripts/bash/change_wallpaper.sh

Script:

#!/bin/bash -
# Get the pid of nautilus
nautilus_pid=$(pgrep -u $LOGNAME -n nautilus)
# If nautilus isn't running, just exit silently
if [ -z "$nautilus_pid" ]; then
    exit 0
fi
# Grab the DBUS_SESSION_BUS_ADDRESS variable from nautilus's environment
eval $(tr '\0' '\n' < /proc/$nautilus_pid/environ | grep '^DBUS_SESSION_BUS_ADDRESS=')
# Check that we actually found it
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
    echo "Failed to find bus address" >&2
    exit 1
fi
# export it so that child processes will inherit it
export DBUS_SESSION_BUS_ADDRESS
HOUR=$(date +%H)
PICDIR="/usr/share/backgrounds/"
#echo "HOUR: $HOUR"
#echo "PICDIR: $PICDIR"
case $HOUR in
21|22|23|00|01|02|03|04|05|06)
/usr/bin/gconftool-2 --type string --set  /desktop/gnome/background/picture_filename $PICDIR"NATURE-ZenLizard.png"
;;
12|13|14|15|16|17|18|19|20)
/usr/bin/gconftool-2 --type string --set  /desktop/gnome/background/picture_filename $PICDIR"Fern_by_aalex04.jpg" 
;;
09|10|11)
/usr/bin/gconftool-2 --type string --set  /desktop/gnome/background/picture_filename $PICDIR"Bon-Echo_wallpaper.jpg"
;;
*)
/usr/bin/gconftool-2 --type string --set  /desktop/gnome/background/picture_filename $PICDIR"Ropey_Photo_by_Bob_Farrell.jpg"
;;
esac

By the looks of things, it’s set to change every 9-10 hours. I only need it to change to a different wallpaper at midnight, and then back again at 7PM.

You can set cron to run a task at specific hours/minutes/days.

The cron command format is as follows;

*    *    *    *    *  command to be executed
┬    ┬    ┬    ┬    ┬
│    │    │    │    │
│    │    │    │    │
│    │    │    │    └───── day of week (0 - 6) (0 is Sunday, or use names)
│    │    │    └────────── month (1 - 12)
│    │    └─────────────── day of month (1 - 31)
│    └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)

So for your command to run every day at midnight it would be;

0 0 * * * SHELL=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin @hourly /share/scripts/bash/change_wallpaper.sh

This is presuming the cron command and script you found works. I can’t test it while in work I’m afraid.

To then get the wallpaper to change back again at 1900hrs (7PM) you will have to use a copy of the command and script but with the second wallpaper. If that makes sense.

The cron command will also differ slightly;

0 19 * * * SHELL=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin @hourly /share/scripts/bash/change_wallpaper.sh

Hopefully the script you found will work, it may need some adjusting but you will need to try it first.

For more information on cron see the wiki or this help guide.