Skip to content

Instantly share code, notes, and snippets.

@snehesht
Last active May 6, 2026 03:11
Show Gist options
  • Select an option

  • Save snehesht/99349b8010abe46cc00db149af7ba7b2 to your computer and use it in GitHub Desktop.

Select an option

Save snehesht/99349b8010abe46cc00db149af7ba7b2 to your computer and use it in GitHub Desktop.
Register AppImage
#!/bin/bash
## Written by AI (Google) - Use at your own risk
# --- Configuration ---
APPIMAGE_PATH="$1"
# Clean name for files (removes spaces/special chars)
APP_NAME=$(basename "$APPIMAGE_PATH" .AppImage | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')
TARGET_DIR="$HOME/Applications"
DESKTOP_ENTRY_DIR="$HOME/.local/share/applications"
ICON_DIR="$HOME/.local/share/icons"
# --- Usage Check ---
if [[ -z "$APPIMAGE_PATH" ]]; then
echo "Usage: $0 path/to/your/app.AppImage"
exit 1
fi
if [[ ! -f "$APPIMAGE_PATH" ]]; then
echo "Error: File '$APPIMAGE_PATH' not found."
exit 1
fi
echo "πŸš€ Registering $APPIMAGE_PATH..."
# 1. Prepare Target Directory & Copy
mkdir -p "$TARGET_DIR"
FINAL_PATH="$TARGET_DIR/$(basename "$APPIMAGE_PATH")"
cp "$APPIMAGE_PATH" "$FINAL_PATH"
chmod +x "$FINAL_PATH"
echo "βœ… Copied to: $FINAL_PATH"
# 2. Extract Metadata (Icon and Mime)
# AppImages can self-extract their internal desktop/icon files
echo "πŸ“¦ Extracting metadata..."
TEMP_EXTRACT=$(mktemp -d)
cd "$TEMP_EXTRACT"
# Try to extract the internal desktop file and icon
"$FINAL_PATH" --appimage-extract "*.desktop" > /dev/null 2>&1
"$FINAL_PATH" --appimage-extract ".DirIcon" > /dev/null 2>&1
# Handle Icon
if [[ -f "squashfs-root/.DirIcon" ]]; then
mkdir -p "$ICON_DIR"
cp "squashfs-root/.DirIcon" "$ICON_DIR/$APP_NAME.png"
ICON_VAL="$APP_NAME"
else
ICON_VAL="utilities-terminal" # Fallback icon
fi
# 3. Create/Overwrite Desktop Entry
DESKTOP_FILE="$DESKTOP_ENTRY_DIR/$APP_NAME.desktop"
cat <<EOF > "$DESKTOP_FILE"
[Desktop Entry]
Name=$(basename "$APPIMAGE_PATH" .AppImage)
Exec="$FINAL_PATH" %u
Icon=$ICON_VAL
Type=Application
Categories=Utility;
Terminal=false
Comment=Registered AppImage
EOF
# 4. Register MIME / Protocol Callbacks
# Check the extracted internal desktop file for MimeType strings
INTERNAL_MIME=$(grep "MimeType=" squashfs-root/*.desktop 2>/dev/null | cut -d'=' -f2)
if [[ -n "$INTERNAL_MIME" ]]; then
# Add MimeType to our new desktop file
echo "MimeType=$INTERNAL_MIME" >> "$DESKTOP_FILE"
echo "πŸ”— Found MimeTypes: $INTERNAL_MIME"
# Register handlers with the system
IFS=';' read -ra MIMES <<< "$INTERNAL_MIME"
for mime in "${MIMES[@]}"; do
if [[ -n "$mime" ]]; then
xdg-mime default "$APP_NAME.desktop" "$mime"
done
done
fi
# 5. Refresh System
update-desktop-database "$DESKTOP_ENTRY_DIR"
echo "βœ… Desktop entry created: $DESKTOP_FILE"
echo "πŸŽ‰ Done! The app is now in your menu and handles its URLs."
# Cleanup
rm -rf "$TEMP_EXTRACT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment