1

I found Terminal command to change desktop wallpaper:

gsettings set org.gnome.desktop.background picture-uri file:///path/to/your/image.png

but this command not working in cron and other desktops like Mate. pgrep gnome-session approach shows nothing for me.

Veronika
  • 75
  • 6
  • 2
    I'm voting to close this question as off-topic because questions about Linux belong on https://unix.stackexchange.com/ If you do ask this over there, please delete this here. – Rob Jan 07 '19 at 13:42
  • 2
    I'm voting against closing it - put your effort into answering questions instead of redirecting users to other pages. – Erki Aring Jan 07 '19 at 14:03
  • 3
    Possible duplicate of [Gsettings with cron](https://stackoverflow.com/questions/10374520/gsettings-with-cron) – Quentin Jan 07 '19 at 14:23
  • 1
    @jww, this question about programming in bash (shell) and development a cross-distro script – Vasin Yuriy Jan 08 '19 at 08:28

1 Answers1

6

You can use dconf to change background. Here is example of simple bash script:

#!/bin/bash

WP="$(find ~+ -type f -exec mimetype {} + 2>/dev/null | awk -F': +' '{ if ($2 ~ /^image\//) print $1 }' | sort -R | tail -30 | shuf -n 1)"

dconf write /org/mate/desktop/background/picture-filename "'${WP}'"

You can find distro-specific key using GUI app - dconf-editor

But to use this script in CRON you need to set session environment variables. Command pgrep gnome-session doesn't work in Mint and other not Gnome desktops. To solve this problem you need to save environment variables of specific user by running command at system startup:

env > ~/cronenv && sed -i '/%s/d' ~/cronenv

now you have cronenv file (without substitutional vars - %s) in users home dir. Just restore them back in cron before running dconf:

*/1 7-21 * * * cd ~/Pictures && env $(cat ~/cronenv | xargs) /path/to/first/script

Use crontab -e to edit cron jobs for current user. All works fine!

Vasin Yuriy
  • 484
  • 5
  • 13