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 🙂

A little facelift

After a good 4 years of serving this blog well, it is time to retire the good old Paperpunch theme.

Heck, it’s been retired by its authors, too!

So long, Paperpunch. Welcome to Nucleare!

It’s pretty much the default theme, I only changed the background color (a dark background, for a change) and the heading font (cause I’m a big fan of Open Sans).

I like it! 🙂

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! 🙂

Eclipse freezes after installing LUA development tools plugin

This was an interesting one, but surprisingly very easy to solve.

After installing the LUA tools as a plugin, Eclipse mysteriously stopped working: what happened was, I would launch Eclipse from a shortcut (I’m using Docky in Ubuntu 13.04, but as it turns out, this is irrelevant), it would show me a LUA development tools splash screen (weird), then the Eclipse workbench… and stop there.

I went on to launch Eclipse from the command line to see what was going on and… I discovered that somehow the eclipse binary had been swapped with another one called LuaDevelopmentTools. Funny thing was, the latter was actually the original eclipse binary. Also, eclipse.ini had been renamed to LuaDevelopmentTools.ini.

Solution:

cd /path/to/eclipse/install/folder
mv eclipse eclipse.bak
mv LuaDevelopmentTools eclipse
mv LuaDevelopmentTools.ini eclipse.ini
mv eclipse.back LuaDevelopmentTools

restarted from the launcher, everything works.

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 background color for content assist pop-ups in Eclipse on Ubuntu

The default grayish tone that is set for selection background in TreeViews on Ubuntu makes text unreadable on my display. Choosing an option among those proposed by Eclipse content assist menus turned into a leap of faith (it usually served me well so, yes, the first option should always be fine! :)).

After looking for an entry among the gazillion appearance-related menus in Eclipse I discovered that no, you can’t change the background color of selected items in TreeViews from within Eclipse. You must change it at system-level, don’t know why.. This StackOverflow question helped me a lot.

So, to change that light gray into a more friendly blue-ish (#55a3ba) without affecting every application in your system you can create a specific GTK theme in a gtkrc file.

Create a file named e.g. .gtkrc-eclipse somewhere (I put it inside my home folder) and write these lines inside it:

style "listitem" {
    base[ACTIVE] = "#55a3ba"
}

class "GtkTreeView" style "listitem"

Then you have to change your Eclipse launcher so that it loads your gtkrc file. To do so in Unity, I usually create a .desktop entry with alacarte (sudo apt-get install alacarte if you don’t have it in your system) and edit it with vim.

All launchers are stored by default inside ~/.local/share/applications, they’re a bunch of files whose names end in .desktop. What I do is launch alacarte (pressing Alt+F2 and typing alacarte), create a new entry in whatever category I find most suitable, set the executable name, path, icon and comment.

Then, I open the file created by alacarte with vim; alacarte creates its launchers in ~/.local/share/applications, they’re called alacarte-made-N.desktop: the most recent is the one you just created, of course, so just ls -ltr ~/.local/share/applications to find out which one is the one you want to edit.

Once I’ve found the correct file, I open it with vim to change the Exec line into this:

Exec=env GTK2_RC_FILES=/usr/share/themes/Ambiance/gtk-2.0/gtkrc:/home/myuser/.gtkrc-eclipse '/home/myuser/eclipse/eclipse'

(it’s all in one line!)

Please note that you can’t use ‘~’ as a placeholder for your home, you must write absolute paths as in /home/myuser/whatever. What you’re doing here is setting a theme for the application (defined in /usr/share/themes/Ambiance/gtk-2.0/gtkrc, but if you use another theme just change this path into the correct one) and overriding it with custom definitions taken from your gtkrc (:/home/myuser/.gtkrc-eclipse, this must be replaced with the actual path to your gtkrc file).

Save the file and change its name into something more mnemonic, like this: mv alacarte-made-XYZ.desktop eclipse.desktop.

Finally, open nautilus on that folder with nautilus ~/.local/share/applications/; drag the file you’ve just created and drop it to Unity’s bar.

Now you can finally enjoy content assist once again 🙂

Play the System Bell as shell commands end in Ubuntu/Debian

This is a nice little trick I started using after switching to Gnome3, as I don’t have the application switcher panel any longer: before, I could put my mouse cursor over that to see a preview of shell windows where a command is running.

Now I should keep moving the cursor to the top-left corner and wait for the animation to show all open windows, which is tedious when you don’t have a precise idea of how long will commands take.

So, the long hated system bell sound comes to rescue!

Just append ; echo -e "\a" after the command you want to run and… voilà, you’re in the event-driven world! 😛

Example:

wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.13.tar.bz2; echo -e "\a"

This command of course won’t do anything if your volume is set to 0 or you explicitly disabled system audio notifications.

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... */
}

Fix the “error while loading shared libraries: libboost_thread.so.1.48.0: cannot open shared object file: No such file or directory” error

Yet another c++ error that isn’t immediate to recover: I wanted to compile and run a program that uses the awesome Boost libraries, but after successfully compiling the program against the libraries I managed to download and install I got the error in the title.

After some googling, I found that you have to add the path to the boost libraries to the environment variable LD_LIBRARY_PATH. You can check whether that’s the problem you have by running your program in a shell like this:

export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
./my_program

Replace /usr/local/lib/ with the path you chose to install boost libraries to (that’s the default path if you installed them as root).

If your program runs fine, there’s your problem!

To make changes permanent in Ubuntu you have to add a new configuration file for ldconfig:

sudo vim /etc/ld.so.conf.d/libboost.conf

(my editor of choice is VIM, and the name of the file itself doesn’t matter)
Add the library path to that file, i.e. /usr/local/lib/.
Save the file, quit and reload your configuration by calling

sudo ldconfig

Note that your LD_LIBRARY_PATH won’t change, but your program will now run!