Skip to content

Instantly share code, notes, and snippets.

@ninogresenz
Last active March 26, 2023 13:06
Show Gist options
  • 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"
@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