3

I have this small bash script which helps use Infinality font rendering options via a more user-friendly Zenity window: http://gnomefiles.org/content/show.php/Infinality+Style+Changer?content=161984

But whenever I launch it I have this "Color Picker" title on Unity Panel together with the icon assigned for "Color Picker" utility.

I wonder why and how this is happening and how I can change it?

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

The .desktop file "/usr/local/share/applications/InfinalitySettings.desktop" contains the following text:

[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;

And here is the contents of "/usr/share/applications/zenity-color-selection.desktop" which has this title and icon:

[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

2 Answers 2

4

I think the problem is that both Zenity scripts are using the same window manager class. You can check this by executing xprop and clicking on each window, respectively.

If you supply Zenity with a WMCLASS you can make sure that the dialog will always be assigned the correct .desktop launcher.

These are the steps you will have to take:

  1. Define a window manager class for the dialog by adding --class=<WMCLASS> to the commandline., e.g.:

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

    You can choose an arbitrary name as long as its unique and not used by any other application/script. I don't know if special characters work, but just out of caution I would stick to alphanumeric characters only.

  2. Append the following line to the .desktop launcher:

    StartupWMClass=InfinalitySettings
    

Here's how you could implement this in your script (I also modified a few other things):

#!/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
9
  • Thanks, it seems you're right. Both have the same: WM_CLASS(STRING) = "zenity", "Zenity" But I'm just a newbie in scripting, could you please more specific? Should I modify the line starting with im="zenity; how? Insert --class and then... something preceded by "=" (equal sign)??? I don't know if I should make up an arbitrary name here like InfinalitySettings or choose one from a set of available options, if any...
    – Sadi
    Jun 9, 2014 at 16:38
  • @Sadi I updated my answer with more details. If you have any more questions, please feel free to ask away. Jun 9, 2014 at 18:32
  • 1
    @Sadi I went over your original script and simplified a few parts for the fun it. I hope you will find it helpful ☺. Jun 9, 2014 at 19:15
  • 1
    Oh, thank you so much for your help! And I'm also relieved ;-) I did "almost" the same but didn't work, so I thought I was doing something stupid. After all it was only because I used quotes in the .desktop launcher wmclass name. It's solved now :-)
    – Sadi
    Jun 9, 2014 at 19:17
  • 1
    @Sadi I must admit that I didn't really check if the script worked before posting it here. In my latest edit I replaced the existing root method with pkexec, which simplifies things quite a bit but has the downside of not being as customizable as gksudo. I am not too familiar with elevating permissions in bash scripts so please take this with a grain of salt. I am certain there are far more elegant solutions out there. Jun 9, 2014 at 20:36
1

That is strange indeed. Without knowing more about where you got the script, I would have to guess. It is possible that the author has simply used the desktop file for gcolorpicker as a template for his own, simply forgetting to change the GenericName and Icon. But it is pure speculation.

If you've installed the script globally, you can look for the desktop file in /usr/share/applications. It should be called something like "infidelity-settings.desktop". If my assumption is correct, this file should contain a line like this: "GenericName=Color Picker" and another line resembling "Icon=gcolorpicker".

If you've installed the file for your user only, then you should find that desktop file in /home/yourusername/.local/share/applications/

1
  • I wrote this script (mostly borrowed from various sources) and even made a DEB package of it ;-) I merely contains the bash script above located at /usr/local/bin/ and a .desktop file located at /usr/local/share/applications/ which I'll also include in the question now. I now suspect that this might be a Unity and/or Zenity bug probably using the other Zenity desktop file located at /usr/share/applications/???
    – Sadi
    Jun 9, 2014 at 12:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .