How to create a launcher on tint2

Tint2 is a simple, light-weighted and highly customizable panel. It was initially made for Openbox but also works very well with other window managers like Gnome or KDE. If you dont know how to install and configure tint2, you can take a look at this link , it covers all the basic things you need to know about tint2. But although the link does talk about the launcher, it actually doesnt work in my experience, so I have figured out another way and I will show you how here.

First of all, you need to install a package named "wmctrl" , which is used to manage windows ( ie openning apps). The package is avaiable in the respiratory of almost every Linux distro so it's an easy task to install. If you are using Ubuntu or other Debian-based distros, just run sudo apt-get install wmctrl. If you use Archlinux, run sudo pacman -S wmctrl

Next you need to create a launch file at /usr/local/bin/launch, run:
 sudo "your-text-editor" /usr/local/bin/launch  

Then paste the following code into it, then save and exit:
 #!/bin/bash  
  # there has to be at least one parameter, the name of the file to execute  
  if [ $# -lt 1 ]  
  then  
   echo "Usage: `basename $0` {executable_name parameters}"  
   exit 1  
  fi  
  # if the program is not running (being managed by wmctrl), then start it  
  [ "`wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1`" ] || (($*&) && (sleep 1))  
  # now let's make sure all related windows are raised and brought to the front  
  for win in `wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1 | cut -d' ' -f1`  
  do  
    wmctrl -i -a $win  
  done  
  exit 0   

After saving the file, you need to make it executable, run:
 sudo chmod +x /usr/local/bin/launch  

From now, you already have a launcher for your tint2 panel. The next thing you have to do is to configure your tint2rc to add the favorite programs to the launcher. In tint2, .desktop files are required for launchers (and are the only way you can launch an application). You can find your .desktop files for the applications in the folder /usr/share/applications/, if there isnt a .desktop file for an app, just create it similar to the already existed ones.

After that, all you need to do is to add the launcher section to your tint2rc ( in the folder /home/.config/tint2/) and do not forget to include the letter "L" into the panel_item variable in the panel section. Here is an example of my own tint2rc, launcher section
 #------------------------------------------  
  #LAUNCHER  
  #------------------------------------------  
  launcher_icon_theme = areao43  
  launcher_padding = 2 2  
  launcher_background_id = 1  
  launcher_icon_size = 20  
  launcher_item_app = /usr/share/applications/firefox.desktop  
  launcher_item_app = /usr/share/applications/anki.desktop  
  launcher_item_app = /usr/share/applications/lxterminal.desktop  
  launcher_item_app = /usr/share/applications/pidgin.desktop  
  launcher_item_app = /usr/share/applications/deadbeef.desktop  
  launcher_item_app = /usr/share/applications/abiword.desktop  
  launcher_item_app = /usr/share/applications/goldendict.desktop  

launcher on tint2 panel
tint2 panel with a launcher on the left
And now everything is done, just restart your tint2 panel and enjoy the new, beautiful tint2 with a launcher.
linux tips and tricks