Created
November 5, 2025 21:35
-
-
Save darmawan01/1be6c4b9caad7d4af9c5d5b5505f3efb to your computer and use it in GitHub Desktop.
Help To Generate AppImage executable app shortcut for Linux
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 | |
| # Helper script to set up an AppImage and make it available in the system menu | |
| # Check if the user provided all required parameters | |
| if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then | |
| echo "Usage: $0 <APP_NAME> <ICON_PATH> <APPIMAGE_PATH>" | |
| echo "Example: $0 Cursor /path/to/icon.png /path/to/application.AppImage" | |
| exit 1 | |
| fi | |
| # Input parameters | |
| APP_NAME="$1" | |
| ICON_PATH="$2" | |
| APPIMAGE_PATH="$3" | |
| # Directory to store AppImages and icons | |
| APP_DIR="$HOME/Applications/$APP_NAME" | |
| # Check if source files exist | |
| if [ ! -f "$APPIMAGE_PATH" ]; then | |
| echo "Error: AppImage not found at $APPIMAGE_PATH" | |
| exit 1 | |
| fi | |
| if [ ! -f "$ICON_PATH" ]; then | |
| echo "Error: Icon not found at $ICON_PATH" | |
| exit 1 | |
| fi | |
| # Check if app directory already exists | |
| if [ -d "$APP_DIR" ]; then | |
| echo "App directory already exists: $APP_DIR" | |
| echo "Skipping file moves, will create/update .desktop file only..." | |
| # Try to find existing AppImage in the directory | |
| APPIMAGE=$(find "$APP_DIR" -maxdepth 1 -name "*.AppImage" -type f | head -n 1) | |
| if [ -z "$APPIMAGE" ]; then | |
| echo "Warning: No AppImage found in $APP_DIR, using provided path..." | |
| APPIMAGE="$APP_DIR/$(basename "$APPIMAGE_PATH")" | |
| else | |
| echo "Found existing AppImage: $APPIMAGE" | |
| fi | |
| # Try to find existing icon in the directory | |
| ICON=$(find "$APP_DIR" -maxdepth 1 \( -name "*.png" -o -name "*.svg" -o -name "*.ico" -o -name "*.xpm" \) -type f | head -n 1) | |
| if [ -z "$ICON" ]; then | |
| echo "Warning: No icon found in $APP_DIR, using provided path..." | |
| ICON="$APP_DIR/$(basename "$ICON_PATH")" | |
| else | |
| echo "Found existing icon: $ICON" | |
| fi | |
| else | |
| # Create app directory | |
| mkdir -p "$APP_DIR" || { | |
| echo "Error: Failed to create directory $APP_DIR" | |
| exit 1 | |
| } | |
| # Move the AppImage to the Applications directory | |
| echo "Moving $APPIMAGE_PATH to $APP_DIR..." | |
| mv "$APPIMAGE_PATH" "$APP_DIR/" || { | |
| echo "Error: Failed to move AppImage" | |
| exit 1 | |
| } | |
| APPIMAGE="$APP_DIR/$(basename "$APPIMAGE_PATH")" | |
| # Move the icon to the Applications directory | |
| echo "Moving $ICON_PATH to $APP_DIR..." | |
| mv "$ICON_PATH" "$APP_DIR/" || { | |
| echo "Error: Failed to move icon" | |
| exit 1 | |
| } | |
| ICON="$APP_DIR/$(basename "$ICON_PATH")" | |
| # Make the AppImage executable | |
| echo "Making $APPIMAGE executable..." | |
| chmod +x "$APPIMAGE" | |
| fi | |
| # Create applications directory if it doesn't exist | |
| mkdir -p "$HOME/.local/share/applications" || { | |
| echo "Error: Failed to create applications directory" | |
| exit 1 | |
| } | |
| # Create a .desktop file | |
| DESKTOP_FILE="$HOME/.local/share/applications/$APP_NAME.desktop" | |
| echo "Creating .desktop file: $DESKTOP_FILE..." | |
| cat > "$DESKTOP_FILE" <<EOF | |
| [Desktop Entry] | |
| Name=$APP_NAME | |
| Exec="$APPIMAGE" %U | |
| Icon=$ICON | |
| Type=Application | |
| Categories=Utility;Application; | |
| Comment=$APP_NAME | |
| EOF | |
| # Make the .desktop file executable | |
| chmod +x "$DESKTOP_FILE" | |
| # Update the system's application database | |
| if command -v update-desktop-database &> /dev/null; then | |
| echo "Updating system application database..." | |
| update-desktop-database "$HOME/.local/share/applications" | |
| else | |
| echo "Warning: update-desktop-database not found, skipping database update" | |
| fi | |
| echo "Setup complete! $APP_NAME is now available in your system menu." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment