mabox-tools/bin/yautostart

82 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# yautostart: Mabox XDG Autostart GUI script
# Copyright (C) 2019 napcok <napcok@gmail.com>
#
case $LANG in
pl*)
TITLE="Edytor autostartu XDG"
DESC="Wybierz programy/usługi, które mają być uruchamiane autamatycznie\nwraz z sesją OpenBox."
ENABLE="wł"
FILE="Plik"
NAME="Nazwa"
COMMENT="Komentarz"
NO_DESC="brak opisu"
CANCEL="--button=Anuluj:1"
OK="--button=Zastosuj:0"
;;
es*)
TITLE="XDG Autostart Editor"
DESC="Elegir apps o servicios para un reinicio en sesión Openbox."
ENABLE="ejecutar"
FILE="Archivo"
NAME="Nombrar"
COMMENT="Comentar"
NO_DESC="sin descripción"
CANCEL="--button=Cancelar:1"
OK="--button=Aceptar:0"
;;
*)
TITLE="XDG Autostart Editor"
DESC="Choose apps/services to autostart with OpenBox session."
ENABLE="run"
FILE="File"
NAME="Name"
COMMENT="Comment"
NO_DESC="no description"
CANCEL="--button=Cancel:1"
OK="--button=OK:0"
;;
esac
config_dir=${XDG_CONFIG_HOME:-$HOME/.config}
# Copy only new files from /etc/xdg/autostart/
mkdir -p $config_dir/autostart
rsync -aq --ignore-existing /etc/xdg/autostart/ $config_dir/autostart/
# check if line starting with Hidden exist, if not add Hidden=false
for f in $config_dir/autostart/*.desktop; do
grep -q "Hidden=" $f && echo "yes" || echo "Hidden=false" >> $f
done
results=$(mktemp --tmpdir autostart.XXXXXXXXXX)
for f in $config_dir/autostart/*.desktop; do
[ "$(grep -m 1 -e '^[[:blank:]]*Hidden' $f | cut -d = -f 2)" == "true" ] && echo false || echo true
echo $f
grep -m 1 -e '^[[:blank:]]*Name=' $f | cut -d = -f 2
#grep -m 1 -e '^[[:blank:]]*Exec' $f | cut -d = -f 2
comment=$(grep -m 1 -e '^[[:blank:]]*Comment=' $f | cut -d = -f 2)
[ ! -z "$comment" ] && echo $comment || echo "$NO_DESC"
done | yad --window-icon=distributor-logo-mabox --width=640 --height=500 --title="$TITLE" --image="gtk-execute" \
--text="$DESC" --list --print-all --bool-fmt="t" \
--checklist --column="$ENABLE:CHK" --column="$FILE:HD" --column="$NAME" --column="$COMMENT" --tooltip-column=4 $CANCEL $OK > $results
if [[ ${PIPESTATUS[1]} -eq 0 ]]; then
i=0
cat $results | while read line; do
eval $(echo $line | awk -F'|' '{printf "export HIDDEN=\"%s\" FILENAME=\"%s\"", $1, $2 }')
[ $HIDDEN == "true" ] && HIDDEN="false" || HIDDEN="true"
echo "Hidden=$HIDDEN, File: $FILENAME"
sed -i'.temp' -e 's/^Hidden.*$/Hidden='"$HIDDEN"'/g' $FILENAME
rm $FILENAME.temp
((i++))
done
unset NAME HIDDEN FILENAME comment
fi
rm -f $results
exit 0