Fix multiple launcher icon issue in Ubuntu unity

I’m so glad I found out how to fix this, because it’s an issue that just kept popping up every now and then.

The issue is this: for some applications, especially (but not necessarily) after upgrades, Unity somehow decides to spawn a new icon every time the app is launched. Thus, you end up with two identical (or in the case of upgrades, very similar) versions of the icon in the Unity launchbar, with the additional annoyance of having one work as a window switcher, and the other working as a new launcher.

Here’s how to fix that.

1. Locate your application’s .desktop file

In Ubuntu this is either inside ~/.local/share/applications or inside /usr/share/applications.

One problem you may have is that you have more than one .desktop file for the same application. If that is the case, remove one (probably the older one).

The .desktop files don’t necessarily match the application name that’s shown when you hover on the launcher (wonderful design idea, duh), so you might need to use grep to find the file.

For example, to find my PyCharm launcher, I had to execute

ls ~/.local/share/applications | grep -i charm

which returned jetbrains-pycharm.desktop, the file that I was looking for.

Removing duplicate .desktop files might be enough to solve the issue, so try launching your app to see if that fixed it. Otherwise, read on.

2. Find your application’sย WM_CLASS

This wasย the core of the issue in my case. To match a window to an application, Unity looks for the window’s WM_CLASS.

To find what your application’s WM_CLASS is, launch your app and run this in a terminal (using a small window for the terminal, leaving your app visible in the background, you’ll see why in a moment):

xprop WM_CLASS

your mouse cursor will turn into a crosshair, and you must click anywhere on your application’s window. You will find something like this in your terminal:

WM_CLASS(STRING) = "sun-awt-X11-XFramePeer", "jetbrains-pycharm-ce"

(this is the output for PyCharm Community Edition). Your WM_CLASS is the most specific string in the list (use your intuition, in this case jetbrains-pycharm-ce is obviously about PyCharm, whereas the other seems to be related to all Java apps in general).

3. Set your application’s WM_CLASS in the .desktop file

Open your .desktop file from Step 1 with a text editor, and either add (if it’s not there already) this line to the bottom, or replace its previous value with the WM_CLASS string from Step 2:

StartupWMClass=jetbrains-pycharm-ce

replacing jetbrains-pycharm-ce with your WM_CLASS, of course.

4. Profit

That’s it! Close all your application windows, and relaunch your app. This time, after you launch the app, you should only have one icon ๐Ÿ™‚

Advertisements

Another wallpaper changer for Gnome and Unity

The previous wallpaper changer that I wrote in Python served me well for the last 2 years, but sometimes it would get stuck with some wallpapers: of the 200 pictures I have in my wallpapers folder (mostly taken from the paper wall), some were definitely being shown more often than others. Has the script developed a taste? Probably! ๐Ÿ™‚

So this time I decided to put together something very quick, but that does a better job at never showing the same picture twice before all pictures in the folder have been set as desktop background.

It comes as a single bash script, there’s no configuration file to set, it picks pictures from a single folder (whereas the Python version could use several), and it moves files to a folder called shown when setting them as desktop background. Not very elegant, but it gets the job done!

Here it is; you can set your wallpapers folder and the refresh interval at the highlighted lines.

#!/bin/bash
#
# WallpaperChanger.sh
# Copyright 2014 Michele Bonazza michele@michelebonazza.com
#
# A simple script to automatically change your wallpaper in Gnome.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

WALLPAPERS_FOLDER=/home/path/to/your/wallpapers
REFRESH_INTERVAL=$((5 * 60)) # change every 5 minutes
MODE="zoom" # one between none, centered, wallpaper, scaled, stretched, zoom, spanned

# Changes the desktop background, and moves it to the "shown" folder so that it's
# not shown again before all wallpapers in the folder have been used.
# arg1 the file name of the file to be set as new background; must be in the
#      current folder
function change_wallpaper() {
  mv $1 shown
  gsettings set org.gnome.desktop.background picture-uri file://$WALLPAPERS_FOLDER/shown/$1
  gsettings set org.gnome.desktop.background picture-options $MODE
}

# Echoes the next wallpaper to be set, picked at random among images in the
# configured folder
function get_next_wallpaper() {
  find . -maxdepth 1 -type f -name "*.png" -o -name "*.jpg" -o -name "*.gif" -o -name "*.jpeg"| shuf -n 1
}

mkdir -p $WALLPAPERS_FOLDER/shown
cd $WALLPAPERS_FOLDER

while true; do
  NEXT_WP=$(get_next_wallpaper)
  
  # have we used all wallpapers?
  if [[ "$NEXT_WP" == "" ]]; then
    # yes, chdir to shown, and move them all back to the parent folder
    cd shown
    # move them to parent folder
    find . -maxdepth 1 -type f -name "*.png" -o -name "*.jpg" -o -name "*.gif" -o -name "*.jpeg" | xargs mv -t ..
    cd ..

    # check again
    NEXT_WP=$(get_next_wallpaper)

    if [[ "$NEXT_WP" == "" ]]; then
      echo "no wallpapers found in $WALLPAPERS_FOLDER, will check again in $REFRESH_INTERVAL seconds..."
      sleep $REFRESH_INTERVAL
      continue
    fi
  fi
  
  echo "changing background to $NEXT_WP"
  change_wallpaper $NEXT_WP
  sleep $REFRESH_INTERVAL
done

As always, I’ve also added this to my pastebin.

Save it as wallpaper_changer.sh, make it executable

chmod +x wallpaper_changer.sh

and add it to your “Startup applications” list, which can be found in Ubuntu’s main menu (the one you use to log out/shut down the computer), or can be brought up from a terminal using

gnome-session-properties

Click “Add”, use whatever name you want and browse to the wallpaper_changer.sh script (wherever you’ve saved it).

Sometimes I found that “Startup applications” doesn’t work: make sure that after having added your script and closed the window you can see an entry called wallpaper_changer.sh.desktop in the output of

ls -l ~/.config/autostart

If it’s not there, remove the entry and try again (I know, I know. The alternative is to fiddle with Upstart or init.d so if you want a GUI, that’s better than nothing!)

You can also change the effect to apply to your wallpapers at line 23 in the script.

Enjoy your new desktops! ๐Ÿ™‚

Disable touch input for a Wacom Bamboo tablet using a Unity launcher (or a Gnome launcher)

I love my Wacom Bamboo graphics tablet, and I really appreciate the fact that it just works in Ubuntu. Palm rejection sort of works, but that “sort of” drives me crazy when I’m using the pen and trigger scrolling by resting my hand on the tablet. I couldn’t find a quick way to disable touch input, something that I can do from a nice GUI window in Mac OS.

After searching some tool to do that, I found the very powerful xsetwacom command, and wrote a very simple script that enables/disables touch.

It goes like this:

#!/bin/bash

DEVICE_ID=$(xsetwacom --list devices | grep TOUCH | egrep -o "id\: [0-9]+" | cut -d" " -f2)

if [[ "off" == $(xsetwacom get $DEVICE_ID touch) ]]; then
    xsetwacom set $DEVICE_ID touch on
else
    xsetwacom set $DEVICE_ID touch off
fi

(should have used awk @line 3, but sometimes I get lazy when writing silly scripts)

Save this file on your user’s home calling it wacom_toggle_touch and make it executable (chmod +x wacom_toggle_touch).

Everytime you run the script, it toggles touch on the tablet. Very neat. But I wanted to just have a graphical button to click, so I created a gnome launcher that just does that; here it is:

[Desktop Entry]
Encoding=UTF-8
Name=Wacom Bamboo Touch
Comment=Toggles touch on a Wacom Bamboo Tablet
Exec=/bin/bash "/home/myuser/wacom_toggle_touch"
Icon=/usr/share/icons/Faenza/devices/scalable/input-tablet.svg
Categories=Application;
Version=1.0
Type=Application
Terminal=0

Name this file wacom-toggle-touch.desktop (the .desktop part is important) and save it to either /usr/share/applications/ or ~/.local/share/applications/, depending on whether you want all users to access the script or only your current user.

I use the cool Faenza theme for my icons, so that explains the icon path @line 6. Here’s the icon if you don’t want to use the theme but you’re looking for an icon that just gets the job done. Download it to some folder and update the path accordingly in the launcher. Also, be sure to update the path to the script @line 5 (for some reason using ~ for your user’s home doesn’t work, you have to type the extended /home/your_username path).

When you’re done, drag the wacom-toggle-touch.desktop file to your Unity bar (I actually use Docky instead, it makes switching between Mac OS and Ubuntu a lot easier on my poor brain) and just click it everytime you want to toggle touch mode!

The same process should work for Gnome as well, just drag the .desktop file to wherever launcher bar you want (assuming Gnome still has launcher bars, they kind of lost me after Gnome 3 so I don’t know).

Change color scheme in Geany

After trying Sublime for a while, and quite liking it, I found myself in the middle of a deep customization of the editor… to make it work like Geany!

For quick editing of local bash/python scripts or configuration files there’s no editor that meets my taste better (I said local cause when dealing with remote files my all-time favorite is vim).

The one thing that I like more in Sublime than in Geany is its look: it’s very elegant, but in the end what I really missed in Geany was a dark editor theme.

I discovered this project on GitHub with several available themes, very easy to install (as in execute-install-script-with-no-options) but.. not that easy to choose from Geany’s interface!

[Update – Mar13] – unjordi posted a nice command line one-liner to get and install the geany-dark color schemes, here it is:

wget -qO- http://geany-dark-scheme.googlecode.com/files/geany_dark_filedefs_20100304_190847.tar.bz2 | tar jxv -C ~/.config/geany/filedefs/

After you’ve downloaded the color schemes and before editing the configuration file as described here below try to restart Geany and check if there’s an entry under View/Editor>Color Schemes>; if it’s there you can choose among all installed color schemes from a nice list! ๐Ÿ™‚

If you’re out of luck (no list for you) you must edit Geany’s configuration file ~/.config/geany/geany.conf and find the color_scheme line. You must specify the whole file name of the color scheme you wish to use, without its path (it must be in the ~/.config/geany/colorschemes folder anyway).

So, to set your theme to tango-dark you shall have this line in your geany.conf file:

color_scheme=tango-dark.conf

Restart Geany and there you have your nice dark theme ๐Ÿ™‚

[Update – Nov13] – a reader had troubles with the configuration file (always reverting to its original state, or not being read correctly by Geany), scroll down to November 5 2013 in the comments if you have the same issues!

Remove the “file edit view go bookmarks help” entries from the Gnome 3 top panel

After running the usual apt upgrade the nautilus menu items suddenly appeared below gnome-shell’s top panel. By below I mean that I have a transparent top bar under which the menu items are showing, but can’t be clicked at all.

Following this post (scroll down to the “Fix Nautilus menu being displayed under the GNOME Shell top bar when using transparent GNOME Shell themes” paragraph) I managed to remove them by simply going to the gnome tweak tool and disabling the Have file manager handle the desktop option under Desktop.

I don’t even know why that option has been set on in the first place…

[Edit]: when disabling the Nautilus desktop management option not only icons will disappear from the desktop, but you you won’t be able to right-click and execute scripts either (and with gnome-shell being very unstable with the latest ATI drivers I very often rely on my gnome-shell restart script, so this is a show stopper).

The only solution I found (and I actually had to struggle a bit, since it doesn’t seem to be a very common issue yet) is to set the top panel background to some opaque image or gradient. Since I installed a gnome-shell theme (you can find the option in the gnome tweak tool under Theme/Shell theme) called Nord, the CSS files to be edited can be found inside ~/.themes/Nord/gnome-shell/, and all styles for the top panel are defined in ~/.themes/Nord/gnome-shell/panel.css.

If you don’t have a custom theme you’ll find the top panel background definition in a file with a path like /usr/share/themes/Ambiance/gtk-3.0/apps/gnome-panel.css (change Ambiance with the name of the GTK+ theme you use).

You must find the #panel definition, and change the background- tags to set an alpha (the fourth in rgba values) of 1.0 like I did:

#panel {
    border: 1px solid rgba(0,0,0,0.2);
    background-gradient-direction: vertical;
    background-gradient-start: rgba(84,84,84,1.0); /* note the 1.0 value */
    background-gradient-end: rgba(168,168,168,1.0);
    /* and so on... */
}

Make your own picture-changing wallpaper in Gnome3

[Edit – April 2014]: I noticed my python script here didn’t do a very good job at not showing the same wallpaper twice before all wallpapers in a folder were shown. Hence, I created another simpler version of the script in bash that does a better job at that. You can find it here

I hoped Gnome3 would have had an integrated function to create custom wallpapers that change throughout the day by picking a folder with your images and choose some refresh interval, but still you have to rely on external scripts or programs.

I’ve been using WallCh for quite some time under Unity, and it suited me well. It was a bit too much for what I wanted to actually do, grabbing pictures in a folder and set them as wallpaper every 3 minutes that is.

Another thing that “annoyed” me is that while in Unity minimized windows are quite the same thing as background processes — in that they just stay on the Unity dash and as long as you don’t hit Alt+Tab they never show up — in Gnome3 I very often go through the list of all open applications, and WallCh by default is always there. I’m not a fan of Alt+Tab in Gnome3: I find it faster to hit Super with my left hand and click on a window I instantly recognize with my right hand than to cycle through small pictures with titles. I don’t know whether WallCh has an option to run in the background, but if it does I didn’t instantly find it and I opted for a little DIY ๐Ÿ˜›

That being said I thought that surely a simple command must exist to just change the wallpaper, and it does! It’s gsettings, with its org.gnome.desktop.background keys. So, to set your ~/Images/1080p/wall_0.png as background you just call

gsettings set org.gnome.desktop.background picture-uri file://$HOME/Images/1080p/wall_0.png
gsettings set org.gnome.desktop.background picture-options zoom

you can just add these two system calls in some simple script in whatever language you like and there you have your custom wallpaper changer!

I came up with a simple python script which is actually a stripped-down version of this nice little script by Romano Giannetti. I simply removed all verbosity and moved the pictures folder definition to a properties file that is checked at every interval, so I never have to change the script itself. If anyone is interested, I’ll post it (it’s less than 50 LOC in the end).

Then, I added the script as a startup application with gnome-session-properties so I finally have my lightweight background wallpaper changer ๐Ÿ™‚

Edit: as Romano himself asked for it, here’s my version of the script: http://pastebin.com/embed_iframe.php?i=UGYNi0K5

Well, if truth be told my version of the script has no error checks whatsoever, but since somebody may try to use this I thought that some information on what’s going on may be helpful. You can list several folders in the configuration file; if you change the configuration file while the script is running the list gets parsed again and reset.