Skip to content

Instantly share code, notes, and snippets.

@ninogresenz
Last active March 26, 2023 13:06
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ninogresenz/868d806723fe0ece9ad70f395f19619e to your computer and use it in GitHub Desktop.
Save ninogresenz/868d806723fe0ece9ad70f395f19619e to your computer and use it in GitHub Desktop.
This script is setting the right icon for all installed chrome apps in KDE's app panel (Icons-only Task Manager). By default it's only showing the chrome icon which is very confusing.
#!/bin/bash
set -e
DIR="$HOME/.local/share/applications"
PATTERN="chrome-*.desktop"
echo -e "Please backup your $PATTERN files in $DIR first. \nContinue? (y/n)"
read continue_process
if [ "$continue_process" != "y" ]; then
exit 1
fi
# checks if the xdotool is installed
if ! command -v xdotool > /dev/null; then
echo "installing xdotool..."
# installs xdotool
yes | sudo pacman -S xdotool
fi
for file in $(find $DIR -type f -name $PATTERN)
do
echo "$file:"
ID=$(grep -m 1 Exec "$file" | sed -E 's/^(.*)--app-id=(\w*).*$/\2/g')
CMD=" \&\& xdotool search --sync --classname $ID set_window --class $ID"
# checks if file has been processed already
if ! grep -q "xdotool search" "$file"; then
echo " append xdotool command..."
# append xdotool command after original command
sed -E -i 's!^(Exec=)(.*)$!\1\2'"${CMD}"'!g' $file
fi
if grep -q "^StartupWMClass" "$file" && ! grep -q "^#StartupWMClass" "$file"; then
echo " disable StartupWMClass..."
# comment all StartupWMClass occurrecnes
sed -E -i 's!^(StartupWMClass.*)$!#\1!g' $file
fi
done
echo "updating desktop database..."
update-desktop-database $DIR
echo "done"
@luvis
Copy link

luvis commented Mar 28, 2022

This is great, thank you for your work! I found it through the following site
https://superuser.com/questions/1015796/in-kde-plasma-5-how-to-i-create-standalone-launchers-desktop-shortcuts-to-web-a
I think it would be a great Idea to write something about what this is. Like a basic readme with the reason for the script and "installation instructions" I use this script a lot, on several computers both home and at work and it saves me loads of time, it's worth it's own github page imo just because it's so simple and it solves a problem that I'm sure many experience. Either way, thanks!

@franciscohoracio
Copy link

:0) Works fine

@jomarinb
Copy link

Nice work! Thanks a lot 😃

@kayzzen01
Copy link

kayzzen01 commented Apr 19, 2022

Really good! It worked on Brave, but I needed to disable option Allow this program to be grouped for Brave. At least KDE lets you manage this option per application. Thanks a lot!

@ninogresenz
Copy link
Author

Thanks a lot for your feedback, folks. I'm happy that it's also helpful for others. :)

@hughsheehy
Copy link

Tried it just now on a fresh manjaro install. Runs fine...doesn't change the situation. Still chrome only icons.

@mdepa91
Copy link

mdepa91 commented Oct 20, 2022

please fix script if file is link:
Could not parse file "/home/marcin/.local/share/applications/org.kicad_pcb.KiCad.desktop": No such file or directory

ls:
/home/marcin/.local/share/applications/org.kicad_pcb.KiCad.desktop -> /var/lib/flatpak/app/org.kicad_pcb.KiCad/current/active/export/share/applications/org.kicad_pcb.KiCad.des

@ninogresenz
Copy link
Author

It somehow also stopped working for me. I figured that the reason (at least for me) was, that there is a StartupWMClass property.
Also, the script is now only considering real files and not symlinks anymore. thx @mdepa91

In general:
This script is changing your *.desktop files and potentially break them. So please make sure you have a backup before starting this script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment