Background
I have a script that changes the wallpaper on my Ubuntu 22 every 5 minutes:
#!/bin/bash
targetDir="/home/pedro/Pictures/Wallpapers"
function get_next_photo() {
# Returns a random file form targetdir
files=( "$targetDir"/* )
echo "${files[RANDOM % ${#files[@]}]}"
}
function set_background() {
# Takes an absolute file path as argument. Need * for spaces in path
bg="$*"
echo "Setting background to $bg"
dconf write "/org/gnome/desktop/background/picture-uri" "'file://$bg'"
}
while :
do
background=$(get_next_photo)
echo "Next background is $background"
set_background $background
sleep 5m
done
My objective is to run this script at startup and to that effect I have created a .dektop
file at ~/.config/autostart/background_changer.desktop
:
[Desktop Entry]
Version=1.0
Name=Wallpaper Changer
Comment=Periodically changes the background wallpaper, taking random images from the Pictures/wallpapers folder.
Exec=/home/mypc/background_changer.sh
Icon=/usr/share/icons/gnome-logo-text.svg
Terminal=false
Type=Application
Categories=Utility;
Permissions of this file:
$ stat background_changer.desktop
File: background_changer.desktop
Size: 296 Blocks: 8 IO Block: 4096 regular file
Device: 10305h/66309d Inode: 5918548 Links: 1
Access: (0775/-rwxrwxr-x) Uid: ( 1000/ mypc) Gid: ( 1000/ mypc)
Access: 2023-01-16 09:55:14.680162348 +0100
Modify: 2023-01-11 15:38:45.036172742 +0100
Change: 2023-01-13 13:09:00.130731451 +0100
Birth: 2023-01-11 15:38:45.036172742 +0100
Problem
However, when I start my computer, nothing happens. Is there a way to verify that the script was started successfully?
Please note that using systemd
is not possible due to the reasons mentioned in this post:
https://askubuntu.com/a/1449904/149504