Skip to content

Instantly share code, notes, and snippets.

@tiriana
Created June 4, 2026 14:25
Show Gist options
  • Select an option

  • Save tiriana/fb66bdd934cc676eea5696a7d96b66b2 to your computer and use it in GitHub Desktop.

Select an option

Save tiriana/fb66bdd934cc676eea5696a7d96b66b2 to your computer and use it in GitHub Desktop.
Ubuntu script to fix duplicate Steam game shortcuts by appending missing StartupWMClass values
#!/bin/bash
# 1. Copy all Steam shortcuts from Desktop to the system applications folder
cp ~/Desktop/*.desktop ~/.local/share/applications/ 2>/dev/null
# 2. Loop through all application shortcuts to fix them
for file in ~/.local/share/applications/*.desktop; do
# Check if the file is a Steam game launcher and is missing the fix
if grep -q "rungameid" "$file" && ! grep -q "StartupWMClass" "$file"; then
# Extract the numerical AppID from the launch URL
appid=$(grep -oP "rungameid/\K[0-9]+" "$file")
# Append the correct window tracking class line to the end of the file
echo "StartupWMClass=steam_app_$appid" >> "$file"
# Print a clean confirmation message to your terminal screen
echo "Fixed: $(basename "$file") (AppID: $appid)"
fi
done
# 3. Refresh Ubuntu's desktop environment database so the icons update immediately
update-desktop-database ~/.local/share/applications/
@tiriana

tiriana commented Jun 4, 2026

Copy link
Copy Markdown
Author

One liner:

cp ~/Desktop/*.desktop ~/.local/share/applications/ 2>/dev/null; for f in ~/.local/share/applications/*.desktop; do if grep -q "rungameid" "$f" && ! grep -q "StartupWMClass" "$f"; then appid=$(grep -oP "rungameid/\K[0-9]+" "$f"); echo "StartupWMClass=steam_app_$appid" >> "$f"; echo "Fixed: $(basename $f) with AppID $appid"; fi; done; update-desktop-database ~/.local/share/applications/

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