아이콘 테마가 다를 때 데스크탑 파일에서 사용할 아이콘 이름, 동일한 응용 프로그램에 대해 다른 이름을 사용하십시오.

아이콘 테마가 다를 때 데스크탑 파일에서 사용할 아이콘 이름, 동일한 응용 프로그램에 대해 다른 이름을 사용하십시오.

질문

데스크톱 파일에서 여러 아이콘을 선택할 수 있는 방법이 있는지 알고 싶습니다. 예를 들어, Android Studio용 데스크톱 파일에는 다음 아이콘 줄이 있습니다.

Icon=/opt/android-studio/bin/studio.png

잘 작동하지만 문제는 항상 똑같은 "studio.png"가 아닌 내가 사용하고 있는 아이콘 테마가 제공하는 아이콘이 되기를 원한다는 것입니다. 나는 그것을 다음과 같이 변경할 수 있다는 것을 알고 있습니다.

Icon=androidstudio

아시다시피 "androidstudio"라는 이름으로 Android 스튜디오 아이콘을 제공하는 아이콘 테마와 잘 작동합니다. 문제는 다양한 아이콘 테마가 다음을 포함하여 Android 스튜디오에 대해 서로 다른 이름의 아이콘을 제공한다는 것입니다.

  • com.google.AndroidStudio
  • 안드로이드 스튜디오
  • 안드로이드 스튜디오
  • 사진관
  • 등.

아이콘 테마가 제공하는 것을 사용할 수 있도록 데스크탑 파일에 이러한 이름을 모두 넣을 수 있는 방법이 있습니까?


내가 시도한 것

일부 데스크톱 파일에서 본 내용을 바탕으로 세미콜론으로 다른 값(예: 아이콘 이름)을 구분하려고 했지만 작동하지 않았습니다.

Icon=com.google.AndroidStudio;studio;androidstudio;

내가 이미 읽은 내용:

답변1

당신이 나타내는 방식은 그것이 작동하는 방식이기도합니다. 예를 들어 일반 아이콘 이름을 제공합니다 androidstudio. 시스템은 먼저 현재 테마가 이러한 아이콘을 제공하는지 확인하고, 그렇지 않은 경우 대체 테마 아이콘을 사용하거나 일반 아이콘을 사용합니다. 따라서 파일에 여러 대체 아이콘을 표시하는 규정이 없습니다 .desktop.

일반적으로 한 번에 하나의 테마만 사용하고 있습니다. 따라서 가장 쉬운 방법은 .desktop애플리케이션 파일의 로컬 복사본에서 사용하려는 아이콘을 하드 코딩하는 것입니다 . 이를 위해 루트가 될 필요는 없습니다. 이러한 로컬 사본은 .local/share/applications시스템 전체 파일 에 존재 하며 이를 대체합니다 .desktop.

어떤 이유로든 테마 전환을 선호하고 애플리케이션에 대한 테마별 아이콘이 있을 때마다 아이콘 파일의 이름을 바꾸거나 복사하여 사용하려는 모든 테마에 일치하는 아이콘이 존재하도록 할 수 있습니다. 이런 방식으로 시스템 전체 테마를 편집하려면 루트여야 합니다.

답변2

@vanadium이 데스크톱 파일에서 동시에 여러 아이콘을 제공할 수 있는 방법이 없으며 아이콘을 하드 코딩하거나 이름을 바꾸거나 복사해야 한다고 말한 후 이에 대한 스크립트를 작성하지 않을 이유가 무엇인지 생각했습니다. 다음 스크립트는 데스크탑 파일을 수정하여 아이콘 테마가 Android 스튜디오에 제공하는 모든 항목으로 아이콘을 설정합니다.

#!/bin/bash

# note 1) run this script when you want to change the icon
# note 2) pass 0 to this script (./script_name 0) to use the studio.png
#   if you want that for some reason
# note 3) before using this script, be sure to edit desktop_file and default_icon variables
# note 4) before using this script, edit the switch (the keyword is 'case' in the script),
#   based on the icon themes you have

# tip: for easier use, go to ~/.bash_aliases and define an alias

desktop_file=~/.local/share/applications/jetbrains-studio.desktop
default_icon=/opt/android-studio/bin/studio.png

function print_use() { echo "Use: $0 0[optional]"; }
function print_done() { echo "android studio icon has changed. enjoy :)"; }

if [[ ! -f $desktop_file ]]; then
    echo "$0: desktop file does not exist. you need to edit this script."
    exit 1
fi

# check and act based on arguments passed to script
if [[ $# -gt 1 ]]; then
    print_use
    exit 1
elif [[ $# -eq 1 ]]; then
    if [[ $1 -eq 0 ]]; then
        sed --in-place "s@^Icon=.*@Icon=$default_icon@" $desktop_file
        print_done
        exit 0
    else
        print_use
        exit 1
    fi
fi


# get the name of the icon theme in use
icon_theme=$(dconf read /org/gnome/desktop/interface/icon-theme)
echo "active icon theme: $icon_theme"
# trim starting and ending single quotes
icon_theme=${icon_theme:1:$((${#icon_theme}-2))}

# choose icon name based on the icon theme name
case $icon_theme in

    Vimix-* | Flat-Remix* | Deepin | Flattery | Gruvbox | Oranchelo | SURU-PLUS* | Korla)
        icon_name="androidstudio"
        ;;

    Tela-red | Uos | Xenlism-Storm)
        icon_name="android-studio"
        ;;

    *)
        echo "no icon found :( ... using the default icon"
        icon_name=$default_icon
        ;;
esac

sed --in-place "s@^Icon=.*@Icon=$icon_name@" $desktop_file
print_done

~/.bash_aliases에 다음 별칭을 정의했으므로 이제 아이콘 테마를 변경할 때마다 터미널에 'u'를 입력하고 Enter 키를 누르기만 하면 됩니다.

alias u="$scripts/android_studio_icon.sh"

관련 정보