Created
July 18, 2025 07:35
-
-
Save naranyala/df8aa5ad1d741eb924b94dd3406697c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # β Require all arguments | |
| if [[ $# -lt 5 ]]; then | |
| echo "Usage:" | |
| echo " $0 <AppName> <ExecCommand> <IconSourcePath> <WorkingDir> <Comment>" | |
| echo "" | |
| echo "Example:" | |
| echo " $0 \"TLauncher\" \"/usr/games/tlauncher/run.sh\" \"~/Downloads/tlauncher.png\" \"/usr/games/tlauncher\" \"Run client for the games\"" | |
| exit 1 | |
| fi | |
| APP_NAME="$1" | |
| EXEC_COMMAND="$2" | |
| ICON_SOURCE="$3" | |
| APP_PATH="$4" | |
| APP_COMMENT="$5" | |
| # π Paths | |
| DESKTOP_DIR="$HOME/.local/share/applications" | |
| ICON_DIR="$HOME/.local/share/icons/hicolor/512x512/apps" | |
| ICON_NAME="${APP_NAME// /-}.png" | |
| DESKTOP_FILE="$DESKTOP_DIR/${APP_NAME// /-}.desktop" | |
| mkdir -p "$DESKTOP_DIR" | |
| mkdir -p "$ICON_DIR" | |
| # πΌοΈ Copy icon to standard location | |
| ICON_SOURCE_EXPANDED=$(realpath "$ICON_SOURCE") | |
| cp -f "$ICON_SOURCE_EXPANDED" "$ICON_DIR/$ICON_NAME" | |
| # π Update icon cache | |
| gtk-update-icon-cache "$HOME/.local/share/icons/hicolor" &>/dev/null || true | |
| # π΅οΈ Detect StartupWMClass (optional) | |
| echo "π Attempting to detect StartupWMClass..." | |
| WMCLASS=$(xprop -name "$APP_NAME" | grep WM_CLASS | awk -F\" '{print $4}' || true) | |
| if [[ -z "$WMCLASS" ]]; then | |
| WMCLASS="${APP_NAME// /-}" | |
| echo "β οΈ Could not detect WM_CLASS. Using fallback: $WMCLASS" | |
| else | |
| echo "β Detected WM_CLASS: $WMCLASS" | |
| fi | |
| # π Write .desktop file | |
| cat > "$DESKTOP_FILE" <<EOF | |
| [Desktop Entry] | |
| Version=1.0 | |
| Type=Application | |
| Name=$APP_NAME | |
| Comment=$APP_COMMENT | |
| Exec=$EXEC_COMMAND | |
| Icon=${APP_NAME// /-} | |
| Terminal=false | |
| Path=$APP_PATH | |
| StartupNotify=true | |
| StartupWMClass=$WMCLASS | |
| EOF | |
| chmod +x "$DESKTOP_FILE" | |
| # π§ Trust and validate | |
| gio set "$DESKTOP_FILE" metadata::trusted true || true | |
| desktop-file-validate "$DESKTOP_FILE" || echo "β οΈ Validation warning (non-fatal)" | |
| # π Refresh desktop DB | |
| update-desktop-database "$DESKTOP_DIR" &>/dev/null || true | |
| echo "β Launcher created: $DESKTOP_FILE" | |
| echo "π You can now pin '$APP_NAME' in your system launcher!" | |
| # EXAMPLE | |
| # | |
| ./create_launcher.sh "TLauncher" \ | |
| "/usr/games/tlauncher/lib/jvm/jre/bin/java -Dfile.encoding=UTF8 -jar /usr/games/tlauncher/starter-core.jar" \ | |
| "/usr/games/tlauncher/tlauncher.png" \ | |
| "/usr/games/tlauncher" \ | |
| "Run client for the games" | |
| # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment