[HowTo] Change screen timeout on lockscreen [KDE]

I created a script that will change screen timeout while screen is locked (Meta+L). Even though there is already a similar thread ‘Lock screen monitor timeout’ I find the solution there less than ideal. It does not change timeout but it only force to turn off the screen once.
My script however change timeout so even if you move your mouse screen will wake up only for a moment.

There are actually two scripts. One that run on lock and one that run on unlock.

timeout_lock.sh

#!/bin/bash

FILE=~/.timeout_info_temp
if [ -f "$FILE" ]; then
    rm -rf ~/.timeout_info_temp
    xset q >> ~/.timeout_info_temp
    xset dpms 30 45 60
else 
    xset q >> ~/.timeout_info_temp
    xset dpms 30 45 60
fi

timeout_unlock.sh

#!/bin/bash

FILE=~/.timeout_info_temp
if [ -f "$FILE" ]; then
    line=$( cat ~/.timeout_info_temp | grep Standby  )

    sta1=$( echo $line | sed 's/^Standby:[[:blank:]]*\([0-9]*\).*/\1/' )
    sta2=$( echo $line | sed 's/^.*Suspend:[[:blank:]]*\([0-9]*\).*/\1/' )
    sta3=$( echo $line | sed 's/^.*Off:[[:blank:]]*\([0-9]*\).*/\1/' )

    # echo "Standby: $sta1"
    # echo "Suspend: $sta2"
    # echo "Off: $sta2"
    
    xset dpms $sta1 $sta2 $sta3
    rm -rf ~/.timeout_info_temp
else
    xset dpms 600 900 1200
    notify-send -t 15000 "[Error]: Cannot read screen timeout temp file!" "Screen timeout set to 10 minutes. Check the script."
fi

Remember to add executable permission for both scripts.

Put them in directory that you won’t delete or modify. eg. ~/scripts/
Now all you just need to add scripts to the screen lock settings.

Notifications > Applications: Configure > Search Screen Saver > Configure Events > run command true > add full path to the scipts: timeout_lock.sh, timeout_unlock.sh

Click OK and the scripts should start working.
This will change timeout to 60 seconds when locked and will restore previous value while unlocked.

1 Like