为什么 bash-zenity 脚本在 Unity Panel 上有该标题,在 Unity Launcher 上有该图标?

为什么 bash-zenity 脚本在 Unity Panel 上有该标题,在 Unity Launcher 上有该图标?

我有这个小的bash 脚本这有助于使用无穷性通过更用户友好的字体渲染选项禅意窗户:http://gnomefiles.org/content/show.php/Infinality+Style+Changer?content=161984

但无论何时启动它,我都会在 Unity 面板上看到这个“颜色选择器”标题以及为“颜色选择器”实用程序分配的图标。

我想知道为什么会发生这种情况,怎么会发生以及我该如何改变它?

在此处输入图片描述

#!/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

答案1

我认为问题在于两个 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

答案2

这确实很奇怪。在不知道您从哪里获得脚本的情况下,我只能猜测。作者可能只是将 gcolorpicker 的桌面文件用作自己的模板,只是忘记更改 GenericName 和 Icon。但这纯粹是猜测。

如果您已全局安装该脚本,则可以在 /usr/share/applications 中查找桌面文件。它应该被称为“infidelity-settings.desktop”。如果我的假设正确,该文件应该包含一行这样的内容:“GenericName=Color Picker”和另一行类似于“Icon=gcolorpicker”的内容。

如果您仅为您的用户安装了该文件,那么您应该在 /home/yourusername/.local/share/applications/ 中找到该桌面文件

相关内容