#!/bin/bash
#
# atool-compress
# script to set screen timeout using xautolock
#on Absolute it is available via spacefm desktop menu
# by Paul Sherman for Absolute Linux, 2018-19 - GPL3
#

setfile="$HOME/.icewm/startup"

TIMESET=$(zenity --list --column="Minutes" --title="Screen timeout" \
--window-icon="/usr/share/pixmaps/timer.svg" --width=200 --height=280 --text="Select time until screen off" 5 10 15 20 30 45 60)

if [ $? == 1 ]; then
 exit
fi

# write the setting into the icewm startup file
ret=`grep "xautolock" "$setfile"`
if [ -z "$ret" ]; then
	echo "/usr/bin/xautolock -time $TIMESET&" >> "$setfile"
else
	sed -i '/xautolock/d' "$setfile"
	echo "/usr/bin/xautolock -time $TIMESET&" >> "$setfile"
fi

# then run the setting for current environment
/usr/bin/xautolock -time $TIMESET&
exit 0
