Thursday, April 25, 2013

Creating a new GNOME screen lock button (or any other applicationbutton)

The reasons are not super important, but I want a screen lock button in my panel. I happen to be using lxpanel, although this should work for adding a screen lock button to the menu of any GNOME system. I could have sworn this existed in the past, but I could not find head nor tail of it anymore. In any case, what I really want is to add a menu item to GNOME. Much of what I did was shameless taken from http://forum.lxde.org/viewtopic.php?f=8&t=31300. What I did is as follows:

  1. Open up a new file /usr/share/applications/screenlock.desktop. Obviously, you can name this whatever you want, and you will probably want to name it appropriately for whatever application you are adding to your menu, although it must end in .desktop.

  2. In this new .desktop file, add the following:
    [Desktop Entry]
    Name=ScreenLock
    Comment=Lock your screen
    Icon=system-lock-screen
    Exec=gnome-screensaver-command --lock
    NoDisplay=false
    Type=Application
    Categories=Settings;DesktopSettings
    
  3. Obviously, change the name, comment, and icon for whatever you want to add. Most importantly, make sure to update Exec to whatever command it is you actually want to execute. You can change the categories, too, although I have not explored them much and don't really know what categories exist.

  4. Now you should have a new menu item. If you have a GNOME menu accessible, you should be able go to Menu -> Preferences and see the new ScreenLock entry. However, what I want is to add it to my panel. I'll describe this for lxpanel, but I believe it should be quite similar for the GNOME 3 panel. Start by right clicking on your panel and going to "Panel Settings."

  5. Click on Panel Applets -> Add and select Application Launch Bar.

  6. From here, you can select the menu item to execute. In this case, I selected Preferences -> ScreenLock and then clicked Add.

That's about it; you should have a screen lock button in your panel now.