web-dev-qa-db-ja.com

bash-zenityスクリプトのUnityパネルにそのタイトルがあり、Unityランチャーにそのアイコンがあるのはなぜですか?

この小さなbash scriptを使用すると、Infinalityフォントレンダリングオプションの使用に役立ちますよりユーザーフレンドリーなZenityウィンドウ: http://gnomefiles.org/content/show.php/Infinality+Style+Changer? content = 161984

しかし、それを起動するたびに、Unityパネルに「Color Picker」ユーティリティに割り当てられたアイコンとともにこの「Color Picker」タイトルがあります。

なぜ、どのようにこれが起こっているのか、どうすれば変更できるのだろうか?

enter image description here

#!/bin/bash
# A simple script to provide a basic, zenity-based GUI to change Infinality Style.
# v.1.2
#
infinality_current=`cat /etc/profile.d/infinality-settings.sh | grep "USE_STYLE=" | awk -F'"' '{print $2}'`
Sudo_password="$( gksudo --print-pass --message 'Provide permission to make system changes: Enter your password to start or press Cancel to quit.' -- : 2>/dev/null )"
# Check for null entry or cancellation.
if [[ ${?} != 0 || -z ${Sudo_password} ]]
then
# Add a zenity message here if you want.
exit 4
fi
# Check that the password is valid.
if ! Sudo -kSp '' [ 1 ] <<<"${Sudo_password}" 2>/dev/null
then
# Add a zenity message here if you want.
exit 4
fi
#
menu(){
im="zenity --width=500 --height=490 --list --radiolist --title=\"Change Infinality Style\" --text=\"Current <i>Infinality Style</i> is\: <b>$infinality_current</b>\n✔ To <i>change</i> it, select any other option below and press <b>OK</b>\n✘ To <i>quit without changing</i>, press <b>Cancel</b>\" "
im=$im" --column=\" \" --column \"Options\" --column \"Description\" "
im=$im"FALSE \"DEFAULT\" \"Use default settings - a compromise that should please most people\" "
im=$im"FALSE \"OSX\" \"Simulate OSX rendering\" "
im=$im"FALSE \"IPAD\" \"Simulate iPad rendering\" "
im=$im"FALSE \"UBUNTU\" \"Simulate Ubuntu rendering\" "
im=$im"FALSE \"LINUX\" \"Generic Linux style - no snapping or certain other tweaks\" "
im=$im"FALSE \"WINDOWS\" \"Simulate Windows rendering\" "
im=$im"FALSE \"WIN7\" \"Simulate Windows 7 rendering with normal glyphs\" "
im=$im"FALSE \"WINLIGHT\" \"Simulate Windows 7 rendering with lighter glyphs\" "
im=$im"FALSE \"Vanilla\" \"Just subpixel hinting\" "
im=$im"FALSE \"CLASSIC\" \"Infinality rendering circa 2010 - No snapping.\" "
im=$im"FALSE \"Nudge\" \"Infinality - Classic with lightly stem snapping and tweaks\" "
im=$im"FALSE \"Push\" \"Infinality - Classic with medium stem snapping and tweaks\" "
im=$im"FALSE \"SHOVE\" \"Infinality - Full stem snapping and tweaks without sharpening\" "
im=$im"FALSE \"SHARPENED\" \"Infinality - Full stem snapping, tweaks, and Windows-style sharpening\" "
im=$im"FALSE \"INFINALITY\" \"Infinality - Standard\" "
im=$im"FALSE \"DISABLED\" \"Act without extra infinality enhancements - just subpixel hinting\" "
}
#
option(){
choice=`echo $im | sh -`
#
if echo $choice | grep "DEFAULT" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"DEFAULT\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "OSX" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"OSX\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "IPAD" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"IPAD\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "UBUNTU" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"UBUNTU\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "LINUX" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"LINUX\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "WINDOWS" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"WINDOWS\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "WIN7" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"WINDOWS7\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "WINLIGHT" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"WINDOWS7LIGHT\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "Vanilla" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"Vanilla\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "CLASSIC" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"CLASSIC\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "Nudge" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"Nudge\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "Push" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"Push\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "SHOVE" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"SHOVE\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "SHARPENED" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"SHARPENED\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "INFINALITY" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"INFINALITY\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
if echo $choice | grep "DISABLED" > /dev/null;
then
Sudo -Sp '' sed -i "s/USE_STYLE=\"${infinality_current}\"/USE_STYLE=\"DISABLED\"/g" '/etc/profile.d/infinality-settings.sh' <<<"${Sudo_password}"
fi
#
}
#
menu
option
#
if test ${#choice} -gt 0; then
echo "Operation completed"
fi
#
exit 0

.desktopファイル「/usr/local/share/applications/InfinalitySettings.desktop」には次のテキストが含まれています。

[Desktop Entry]
Name=Infinality Style Changer
GenericName=Infinality Settings
Exec=/usr/local/bin/InfinalitySettings
Icon=gnome-settings-font
Terminal=false
Type=Application
Categories=GTK;GNOME;System;Settings;Fonts;

そして、このタイトルとアイコンを持つ「/usr/share/applications/zenity-color-selection.desktop」の内容は次のとおりです。

[Desktop Entry]
Encoding=UTF-8
Type=Application
Categories=Graphics;2DGraphics;RasterGraphics;GTK;
Name=Color Picker
GenericName=Color Picker
Comment=Pick a color from palette or any color on your screen
NotShowIn=KDE;
Icon=preferences-color
#Icon=applications-graphics
Exec=zenity --color-selection --show-palette
Terminal=false
3
Sadi

問題は、両方のZenityスクリプトが同じウィンドウマネージャークラスを使用していることだと思います。これを確認するには、それぞれxpropを実行し、各ウィンドウをクリックします。

ZenityにWMCLASSを提供する場合、ダイアログに常に正しい.desktopランチャーが割り当てられることを確認できます。

これらはあなたがとらなければならないステップです:

  1. --class=<WMCLASS>をコマンドラインに追加して、ダイアログのウィンドウマネージャークラスを定義します。例:

    zenity --class=InfinalitySettings --width=500 --height=490 [...]
    

    一意であり、他のアプリケーション/スクリプトで使用されていない限り、任意の名前を選択できます。特殊文字が機能するかどうかはわかりませんが、注意してください。英数字のみに固執します。

  2. .desktopランチャーに次の行を追加します。

    StartupWMClass=InfinalitySettings
    

これをスクリプトに実装する方法を次に示します(他にもいくつかの変更を加えました)。

#!/bin/bash
# A simple script to provide a basic, zenity-based GUI to change Infinality Style.
# v.1.3

# tip: use http://www.shellcheck.net/ to avoid common problems

## variables

InfinalityConfig="/etc/profile.d/infinality-settings.sh"
InfinalityCurrent="$(cat "$InfinalityConfig" | grep "USE_STYLE=" | awk -F\" '{print $2}')" 
#                  ↑ "$()" is safer than ``

## dialog

# assign descriptions and other dialog elements
# makes the script easier to read

WmClass="InfinalitySettings"


TxtMain="Current <i>Infinality Style</i> is\: <b>$InfinalityCurrent</b>
✔ To <i>change</i> it, select any other option below and press <b>OK</b>
✘ To <i>quit without changing</i>, press <b>Cancel</b>"

Title="Change Infinality Style"

## functions

select_style(){
    Choice="$(zenity --class="$WmClass" --width=500 --height=490 --list --radiolist \
    --title="$Title" --text="$TxtMain" \
    --column="" --column="Options" --column="Descriptions" \
    "FALSE" "DEFAULT" "Use default settings - a compromise that should please most people" \
    "FALSE" "OSX" "Simulate OSX rendering" \
    "FALSE" "IPAD" "Simulate iPad rendering" \
    "FALSE" "UBUNTU" "Simulate Ubuntu rendering" \
    "FALSE" "LINUX" "Generic Linux style - no snapping or certain other tweaks" \
    "FALSE" "WINDOWS" "Simulate Windows rendering" \
    "FALSE" "WIN7" "Simulate Windows 7 rendering with normal glyphs" \
    "FALSE" "WINLIGHT" "Simulate Windows 7 rendering with lighter glyphs" \
    "FALSE" "Vanilla" "Just subpixel hinting" \
    "FALSE" "CLASSIC" "Infinality rendering circa 2010 - No snapping." \
    "FALSE" "Nudge" "Infinality - Classic with lightly stem snapping and tweaks" \
    "FALSE" "Push" "Infinality - Classic with medium stem snapping and tweaks" \
    "FALSE" "SHOVE" "Infinality - Full stem snapping and tweaks without sharpening" \
    "FALSE" "SHARPENED" "Infinality - Full stem snapping, tweaks, and Windows-style sharpening" \
    "FALSE" "INFINALITY" "Infinality - Standard" \
    "FALSE" "DISABLED" "Act without extra infinality enhancements - just subpixel hinting" \
    )"
    RET_YAD="$?"                # get exit code

    if [[ "$RET_YAD" != "0" ]]  # if exit code != 0 (e.g. user closed window, hit 'cancel')
      then
          echo "Aborted."
          exit 1
    Elif [[ -z "$Choice" ]]
      then
          echo "No option selected. Exiting."
          exit 0
    fi

    echo "User chose: $Choice"
}

set_style(){
    pkexec --user root sed -i "s/USE_STYLE=\"$InfinalityCurrent\"/USE_STYLE=\"$Choice\"/g"\
     "$InfinalityConfig"
    RET_PKEXEC="$?"

    if [[ "$RET_PKEXEC" != "0" ]]
      then
          exit 1
          # Add a zenity message here if you want.
      else
          exit 0
    fi
}

## main

select_style
set_style
4
Glutanimate

それは確かに奇妙です。スクリプトの入手場所について詳しく知ることなく、推測する必要があります。著者は、単にgcolorpickerのデスクトップファイルを自分のテンプレートとして使用し、単にGenericNameとIconを変更するのを忘れている可能性があります。しかし、それは純粋な憶測です。

スクリプトをグローバルにインストールした場合は、/ usr/share/applicationsでデスクトップファイルを検索できます。 「infidelity-settings.desktop」のような名前にする必要があります。私の仮定が正しい場合、このファイルには「GenericName = Color Picker」のような行と「Icon = gcolorpicker」に似た別の行が含まれているはずです。

ユーザー専用のファイルをインストールした場合、そのデスクトップファイルは/home/yourusername/.local/share/applications/にあります。

1