notes for nerds – pc, server, phones, apps

notes4nerds

— notes.h87.at —

Desktop Entry – Apps in Linux einbinden

Um in Linux als Programm/App sichtbar/registriert zu sein, brauchen einen „Desktop Entry“ unter den Programmen/Apps unter

~/.local/share/applications/

Beispiel für eine Desktop Entry Datei

[Desktop Entry]
Name=Inkscape
Exec=/opt/inkscape/Inkscape.AppImage %u
Icon=/opt/inkscape/inkscape-logo.svg
Comment=Draw Freely
Type=Application
Terminal=false
Encoding=UTF-8
Categories=Utility;
StartupNotify=true
StartupWMClass=org.inkscape.Inkscape

Skripte für Desktop Entries

Skript um Bilder aus Appimage zu generieren

#!/bin/bash
set -e
set -o pipefail

APPIMAGE_PATH=$1

if [ -z "$APPIMAGE_PATH" ]; then
    echo "Missing argument: appimage"
    exit 1
fi

if [ ! -f "$APPIMAGE_PATH" ]; then
    echo "File not found: $APPIMAGE_PATH"
    exit 1
fi

TEMP_SQUASHFS_PATH=$(mktemp -d)
APPIMAGE_FULLPATH=$(readlink -e "$APPIMAGE_PATH")
APPIMAGE_FILENAME=$(basename "$APPIMAGE_PATH")
APP_NAME="${APPIMAGE_FILENAME%.*}"
DESKTOP_ENTRY_PATH="${HOME}/.local/share/applications/$APP_NAME.desktop"
ICON_FOLDER="${HOME}/.local/share/icons"
mkdir -p "${ICON_FOLDER}"

if [ "$2" == "--remove" ]; then
    rm -f "$DESKTOP_ENTRY_PATH"
    find "${ICON_FOLDER}" -maxdepth 1 -type f -name "$APP_NAME.*" -delete
    echo "Removed"
    exit 0
fi

pushd $TEMP_SQUASHFS_PATH
"$APPIMAGE_FULLPATH" --appimage-extract > /dev/null
cd squashfs-root/

echo "Choose icon: "
mapfile -t FILENAMES < <(find -L . -maxdepth 1 -type f \( -iname '*.png' -o -iname '*.svg' \))
i=1
for filename in "${FILENAMES[@]}"
do
    printf " %d) %s\n" "$i" "$filename"
    i=$((i + 1))
done

read -r SELECTED_INDEX

ICON_SRC=${FILENAMES[$((SELECTED_INDEX - 1))]}
ICON_EXT="${ICON_SRC##*.}"
ICON_DST="${ICON_FOLDER}/$APP_NAME.$ICON_EXT"
cp "$ICON_SRC" "$ICON_DST"

cat <<EOT > "$DESKTOP_ENTRY_PATH"
[Desktop Entry]
Name=$APP_NAME
StartupWMClass=$APP_NAME
Exec="$APPIMAGE_FULLPATH"
Icon=$ICON_DST
Type=Application
Terminal=false
EOT

popd

rm -rf $TEMP_SQUASHFS_PATH

echo "Created"

Skript Kemi

#!/bin/bash

# Überprüfen, ob die Datei als Argument übergeben wurde
if [ „$#“ -ne 2 ]; then
echo „Benutzung: $0 “
exit 1
fi

SCRIPT_PATH=$1
STARTER_NAME=$2

# Basisverzeichnis für KDE-Starter
STARTER_DIR=“$HOME/.local/share/applications“

# Starter-Datei erstellen
STARTER_FILE=“$STARTER_DIR/$STARTER_NAME.desktop“

# Inhalt für die Starter-Datei
echo „[Desktop Entry]“ > „$STARTER_FILE“
echo „Type=Application“ >> „$STARTER_FILE“
echo „Name=$STARTER_NAME“ >> „$STARTER_FILE“
echo „Exec=$SCRIPT_PATH“ >> „$STARTER_FILE“
echo „Icon=utilities-terminal“ >> „$STARTER_FILE“ # Hier kann das Icon angepasst werden
echo „Terminal=false“ >> „$STARTER_FILE“
echo „Categories=Utility;“ >> „$STARTER_FILE“
echo „Comment=Starte $STARTER_NAME“ >> „$STARTER_FILE“

# Berechtigungen für die Datei setzen
chmod +x „$STARTER_FILE“

echo „Starter für $STARTER_NAME wurde erstellt: $STARTER_FILE“

The table below lists all Main Categories.1

Main CategoryDescriptionNotes
AudioVideoApplication for presenting, creating, or processing multimedia (audio/video) 
AudioAn audio applicationDesktop entry must include AudioVideo as well
VideoA video applicationDesktop entry must include AudioVideo as well
DevelopmentAn application for development 
EducationEducational software 
GameA game 
GraphicsApplication for viewing, creating, or processing graphics 
NetworkNetwork application such as a web browser 
OfficeAn office type application 
ScienceScientific software 
SettingsSettings applicationsEntries may appear in a separate menu or as part of a „Control Center“
SystemSystem application, „System Tools“ such as say a log viewer or network monitor 
UtilitySmall utility application, „Accessories“ 

https://askubuntu.com/questions/1328196/how-can-i-create-a-desktop-entry-for-an-appimage

  1. Registered Categories for Linux/Unix Systems defined by freedesktop.org
    https://specifications.freedesktop.org/menu/latest/category-registry.html ↩︎

Beitrag veröffentlicht

in

von

Schlagwörter:

Kommentare

2 Antworten zu „Desktop Entry – Apps in Linux einbinden“

  1. Avatar von kemi
    kemi

    Ein bisschen simpler ohne schnick schnack geht es so, geht aich für scripte wie starter.sh

    #!/bin/bash

    # Überprüfen, ob die Datei als Argument übergeben wurde
    if [ „$#“ -ne 2 ]; then
    echo „Benutzung: $0 “
    exit 1
    fi

    SCRIPT_PATH=$1
    STARTER_NAME=$2

    # Basisverzeichnis für KDE-Starter
    STARTER_DIR=“$HOME/.local/share/applications“

    # Starter-Datei erstellen
    STARTER_FILE=“$STARTER_DIR/$STARTER_NAME.desktop“

    # Inhalt für die Starter-Datei
    echo „[Desktop Entry]“ > „$STARTER_FILE“
    echo „Type=Application“ >> „$STARTER_FILE“
    echo „Name=$STARTER_NAME“ >> „$STARTER_FILE“
    echo „Exec=$SCRIPT_PATH“ >> „$STARTER_FILE“
    echo „Icon=utilities-terminal“ >> „$STARTER_FILE“ # Hier kann das Icon angepasst werden
    echo „Terminal=false“ >> „$STARTER_FILE“
    echo „Categories=Utility;“ >> „$STARTER_FILE“
    echo „Comment=Starte $STARTER_NAME“ >> „$STARTER_FILE“

    # Berechtigungen für die Datei setzen
    chmod +x „$STARTER_FILE“

    echo „Starter für $STARTER_NAME wurde erstellt: $STARTER_FILE“

    ——————————————————————————-

    benutzung:

    create.desktop.starter.sh programm.appimage „mein Programm“

    1. Avatar von kemi
      kemi

      danach kann mann noch das icon manuell ändern und falls es nicht aktuallisiert kann mann es so machen:

      cd ~/.local/share/applications/
      mv programm.desktop ..
      mv ../programm.desktop .

Schreibe einen Kommentar