Let's have an easy example:
I run a script which is setting a program either to mode "on" (= 1) or to mode "off" (= 0). The script is getting actuated by a simple click on the regarding .desktop
-file.
The script looks like that:
#!/bin/bash
DESKT=/home/user/program.desktop
if [ $(systemctl --user status program | grep -c running) = 0 ]; then
systemctl --user start program
echo "Icon=program_active" >> "$DESKT"
echo "Name=Program working" >> "$DESKT"
else
systemctl --user stop program
echo "Icon=Program_inactive" >> "$DESKT"
echo "Name=Program stopped" >> "$DESKT"
fi
The .desktop-file looks like that:
[Desktop Entry]
Type=Application
Name=Program
Exec=program
Icon=program-inactive
My question now is:
If I switch on my program by actuating the .desktop
-file, the name of the .desktop
-file is getting changed to "Program working" what is fully correct! Unfortunately, the previous icon ("program_inactive
") doesn't get changed to the now needed icon "program_active
".
Instead of replacing the inactive-icon with the correct active-icon, there will be written a completely new line with "Icon=program_active
" instead of replacing the existing line "Icon=program_inactive
". Because of that, there are now two lines with "Icon=blabla
" what is completely useless of course.
What do I have to do to replace the existing icon-line instead of writing a useless new line? Thanks a lot for your ideas!
Try overwriting the file instead.
Explanation:
The
cat <<EOF
will copy anything until the nextEOF
by itself, interpreting variables.