Last active
July 31, 2025 14:54
-
-
Save camilajenny/2963154569d96a4f46b33db4ec91db07 to your computer and use it in GitHub Desktop.
Create a desktop entry and extract an icon from an AppImage file ποΈ
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
| #!/bin/bash | |
| # Usage: ./install-appimage.sh /path/to/MyApp.AppImage | |
| set -e | |
| APPIMAGE_PATH="$1" | |
| if [[ -z "$APPIMAGE_PATH" || ! -f "$APPIMAGE_PATH" ]]; then | |
| echo "Usage: $0 /path/to/AppImage" | |
| exit 1 | |
| fi | |
| APPDIR_NAME=$(basename "$APPIMAGE_PATH" .AppImage) | |
| APPDIR="$HOME/.local/share/appimage/$APPDIR_NAME" | |
| DESKTOP_ENTRY_DIR="$HOME/.local/share/applications" | |
| DESKTOP_ENTRY_PATH="$DESKTOP_ENTRY_DIR/$APPDIR_NAME.desktop" | |
| ICON_DIR="$HOME/.local/share/icons" | |
| ICON_PATH="$ICON_DIR/$APPDIR_NAME.png" | |
| mkdir -p "$APPDIR" | |
| mkdir -p "$ICON_DIR" | |
| # Copy AppImage into target directory | |
| cp "$APPIMAGE_PATH" "$APPDIR/$APPDIR_NAME.AppImage" | |
| chmod +x "$APPDIR/$APPDIR_NAME.AppImage" | |
| # Extract icon | |
| # We'll use the --appimage-extract feature if available | |
| cd "$APPDIR" | |
| "./$APPDIR_NAME.AppImage" --appimage-extract > /dev/null | |
| ICON_CANDIDATE=$(find squashfs-root -name "*.png" | head -n 1) | |
| if [[ -n "$ICON_CANDIDATE" ]]; then | |
| cp "$ICON_CANDIDATE" "$ICON_PATH" | |
| else | |
| echo "Warning: Could not extract icon. Using fallback." | |
| ICON_PATH="/usr/share/icons/hicolor/64x64/apps/application-default-icon.png" | |
| fi | |
| cd - | |
| # Create desktop entry | |
| cat > "$DESKTOP_ENTRY_PATH" <<EOF | |
| [Desktop Entry] | |
| Name=$APPDIR_NAME | |
| Exec=$APPDIR/$APPDIR_NAME.AppImage | |
| Icon=$ICON_PATH | |
| Type=Application | |
| Categories=Utility; | |
| StartupNotify=true | |
| Terminal=false | |
| EOF | |
| chmod +x "$DESKTOP_ENTRY_PATH" | |
| echo "β Desktop entry created: $DESKTOP_ENTRY_PATH" | |
| echo "π You can now find '$APPDIR_NAME' in your application 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
| #!/bin/bash | |
| # Usage: | |
| # ./move_appimage.sh /path/to/AppImage /target/folder | |
| # the paths can be relative thx to realpath | |
| set -e | |
| APPIMAGE_PATH=$(realpath "$1") | |
| TARGET_DIR=$(realpath "$2") | |
| if [[ -z "$APPIMAGE_PATH" || -z "$TARGET_DIR" ]]; then | |
| echo "Usage: $0 /path/to/AppImage /target/folder" | |
| exit 1 | |
| fi | |
| if [[ ! -f "$APPIMAGE_PATH" ]]; then | |
| echo "Error: AppImage not found at $APPIMAGE_PATH" | |
| exit 1 | |
| fi | |
| mkdir -p "$TARGET_DIR" | |
| APPIMAGE_NAME=$(basename "$APPIMAGE_PATH") | |
| TARGET_PATH="$TARGET_DIR/$APPIMAGE_NAME" | |
| echo "Moving $APPIMAGE_PATH to $TARGET_PATH ..." | |
| mv "$APPIMAGE_PATH" "$TARGET_PATH" | |
| chmod +x "$TARGET_PATH" | |
| # Find and update the desktop entry (if exists) | |
| # We try to find .desktop files that have Exec= pointing to the old path or app name | |
| DESKTOP_DIR="$HOME/.local/share/applications" | |
| APPNAME="${APPIMAGE_NAME%.*}" # remove extension for matching | |
| echo "Searching for desktop entries to update..." | |
| UPDATED=0 | |
| shopt -s nullglob | |
| for desktopfile in "$DESKTOP_DIR"/*.desktop; do | |
| if grep -q "Exec=.*$APPNAME" "$desktopfile"; then | |
| echo "Updating $desktopfile" | |
| # Escape slashes for sed | |
| NEWPATH_ESCAPED=$(echo "$TARGET_PATH" | sed 's/\//\\\//g') | |
| sed -i "s|Exec=.*$APPNAME.*|Exec=$NEWPATH_ESCAPED|" "$desktopfile" | |
| UPDATED=1 | |
| fi | |
| done | |
| if [[ $UPDATED -eq 0 ]]; then | |
| echo "Warning: No desktop entry found to update." | |
| else | |
| echo "Desktop entry updated." | |
| fi | |
| echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment