Page 1 of 1

[SOLVED] Can't get screensaver script to run at start up

Posted: Sun Feb 10, 2019 6:02 pm
by Huxley
Linux Mint Mate 19

I'm trying to run a script ( which uses 'feh' and 'xprintidle' to act as a slideshow screensaver. The script is required to be in the same directory as the images to be used in the slldeshow, which on my pc is in Pictures/Wallpapers/. I have given the script the permissions 755, and have disabled the mate-screensaver.

To run in terminal I use the command:

Code: Select all

 ~/Pictures/Wallpapers/ n
where n is the number of seconds of inactivity before the screensaver starts. When 'n' is omitted, the default time of 60 seconds is applied. This runs perfectly without issues. However I can't make it work as a cron job.

I've tried (as user as root):

Code: Select all

crontab -e
@reboot /full/path/to/
@reboot /full/path/to/ n e.g. 60
@reboot '/full/path/to/ 60'
@reboot "/full/path/to/ 60" 
I've also tried using a sleep delay for all of the above to make sure my DE was fully up and unnng before starting the script, e.g.

Code: Select all

@reboot sleep 90 && /full/path/to/
None of which worked. I then tried adding the full path of the script to 'Startup Applications Preferences' GUI. This did work, but without being able to set 'n' I'm stuck with the screensaver starting after the default 60 seconds, which is too fast. I tried adding 'n' after / and putting the entire string into single or double quotation marks, but neither helped.

Thirdly, I found that it's possible to autostart a script by placing it in:

Code: Select all

However, I don't have /etc/rc.d/. I have:

Code: Select all

/rc0.d, rc1.d rc2.d ....rc6.d
None of which contain a /rc.local/ diectory

Any ideas what I'm doing wrong?

Here is the script:

Code: Select all


# url: ###
# This script is licensed under GNU GPL version 2.0 or above

# Uses elements from
# Copyright (c) 2011 at gmail com
# url:
# This script is licensed under GNU GPL version 2.0 or above

# Description: ####
# needs xprintidle and feh to work.

# HOW TO USE: Start the script with the number of seconds you want the checks
# for fullscreen to be done. Example:
# "./ 120"

# enumerate all the attached screens
while read id
    displays="$displays $id"
done< <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')

DIR=$( cd "$( dirname "$0" )" && pwd)


    # loop through every display looking for a fullscreen window
    for display in $displays
        #get id of active window and clean output
        activ_win_id=`DISPLAY=:0.${display} xprop -root _NET_ACTIVE_WINDOW`
        # Check if Active Window (the foremost window) is in fullscreen state
        isActivWinFullscreen=`DISPLAY=:0.${display} xprop -id $activ_win_id | grep _NET_WM_STATE_FULLSCREEN`
            if [[ "$isActivWinFullscreen" != *NET_WM_STATE_FULLSCREEN* ]];then
                feh -x -F -r -Y -Z -z -A slideshow -D 7 -d "$DIR"

# If argument empty, use 60 seconds as default.
if [ -z "$1" ];then

# If argument is not integer quit.
if [[ $1 = *[^0-9]* ]]; then
    echo "The Argument \"$1\" is not valid, not an integer"
    exit 1


cd "$DIR"
while sleep $((1)); do
    if [ $idle -ge $IDLE_TIME ]; then

Re: Can't get screensaver script to run at start up

Posted: Mon Feb 11, 2019 3:43 am
by smurphos
In Cinnamon it works fine from Startup applications. I've named my copy of the script and used a very short idle delay for testing purposes.


The associated desktop file that is created.

Code: Select all

[Desktop Entry]
Exec=/mnt/backup_drive/Pictures/Wallpapers/Desktop/City_&_Modern/ 5
Comment[en_GB]=No description
This also works fine and would be needed if the path included any spaces.

Code: Select all

Exec="/mnt/backup_drive/Pictures/Wallpapers/Desktop/City_&_Modern/" 5
Why is it not working from a crontab?

Using a root crontab will be one issue. The script appears to be looking for displays associated with the user running the script. There won't be any associated with root. I suspect it wouldn't work from a user crontab either without specifying environment variables ...

Anyway an autostart entry is the right place for this as I think it might have issues running if it kicks off before a user has logged in.

Alternatively just edit the default display value in the script so it's not 60.

# If argument empty, use 60 seconds as default.

Code: Select all

if [ -z "$1" ];then

Re: Can't get screensaver script to run at start up

Posted: Mon Feb 11, 2019 9:30 am
by Huxley
Thanks, smurphos. I amended ~/.config/autostart/ with the line:

Code: Select all

and now everything works great.

I kicked myself for not finding the default delay in the script, but will pay closer attention next time.
Thanks again for your help.