Created
July 18, 2025 06:55
-
-
Save naranyala/b3d6e7cfb92f4f00562a78ded1923a97 to your computer and use it in GitHub Desktop.
make android-studio linux globally available, and can be pinned on system launcher
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 | |
| # β Input validation | |
| if [[ $# -ne 2 ]]; then | |
| echo "Usage: $0 /path/to/android-studio/bin/studio.sh /path/to/icon.png" | |
| exit 1 | |
| fi | |
| ANDROID_EXEC="$1" | |
| ICON_PATH="$2" | |
| # π Validate paths | |
| if [[ ! -x "$ANDROID_EXEC" ]]; then | |
| echo "β Executable not found or not executable: $ANDROID_EXEC" | |
| exit 1 | |
| fi | |
| if [[ ! -f "$ICON_PATH" ]]; then | |
| echo "β Icon not found: $ICON_PATH" | |
| exit 1 | |
| fi | |
| # π·οΈ Extract WM_CLASS from running Android Studio (fallback to known value if not detected) | |
| echo "π΅οΈ Detecting StartupWMClass..." | |
| DEFAULT_WMCLASS="jetbrains-studio" | |
| DETECTED_WMCLASS=$(xprop -name "Android Studio" | grep "WM_CLASS" | awk -F\" '{print $4}' || echo "$DEFAULT_WMCLASS") | |
| # π Target desktop entry location | |
| APP_DIR="$HOME/.local/share/applications" | |
| DESKTOP_FILE="$APP_DIR/android-studio.desktop" | |
| mkdir -p "$APP_DIR" | |
| # π Write the desktop entry | |
| cat > "$DESKTOP_FILE" <<EOF | |
| [Desktop Entry] | |
| Version=1.0 | |
| Type=Application | |
| Name=Android Studio | |
| Exec=$ANDROID_EXEC %f | |
| Icon=$ICON_PATH | |
| Terminal=false | |
| Categories=Development;IDE; | |
| StartupNotify=true | |
| StartupWMClass=$DETECTED_WMCLASS | |
| EOF | |
| chmod +x "$DESKTOP_FILE" | |
| # π Update desktop DB | |
| update-desktop-database "$APP_DIR" &>/dev/null || true | |
| echo "β Android Studio shortcut created at: $DESKTOP_FILE" | |
| echo "π You should now be able to pin it to your system launcher." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment