-
-
Save ninogresenz/868d806723fe0ece9ad70f395f19619e to your computer and use it in GitHub Desktop.
#!/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" |
Thanks a lot for your feedback, folks. I'm happy that it's also helpful for others. :)
Tried it just now on a fresh manjaro install. Runs fine...doesn't change the situation. Still chrome only icons.
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
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.
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!