Linux Desktop Invasion: Switch your desktop environment with a script and a smile

With just a single command, you can switch desktop environments. If you think that sounds too easy, then you need to check out this latest installment of the Linux Desktop Invasion.

Linux Desktop Invasion
The Linux desktop is full of surprises—both good and bad. In an effort to highlight the good and show you how to troubleshoot the bad, Jack Wallen Jr. has created a regular series called the Linux Desktop Invasion. In this series, Jack offers tips, tricks, and tweaks to make your Linux desktop simpler, more efficient, and more enjoyable.

In this installment, the tip of the week is how to switch between different desktop environments with a single command. To round out the top five tips for this week, Jack also describes how to disable the [Ctrl][Alt][Delete] reboot key combination, how to deal with a problematic scroll wheel, how to cut and paste Linux-style, and how to use the windows shading a la Mac.

The old switcharoo
More often than not, in this niche-filled marketplace, there are just too many choices. You’ve got to decide between Coke and Pepsi, paper and plastic, CNN and Fox News, X-Box and GameCube, .NET and Java, and GNOME and KDE. The beauty of most Linux distributions is that when it comes to desktop environments, you don’t have to choose—you can have your Coke and Pepsi too. Here’s how.

When your Linux box is set up with runlevel=3 (text-based login), the method of switching between desktop environments is not readily apparent. However, switching between desktop environments is a simple task if you know what tools and/or files to look for. There are two ways you can change the desktop environment: command-line or GUI. The first method, command-line, actually offers a couple of different methods for making this change. The first command-line option uses the .xinitrc file, which is one of the old-school methods of managing the desktop choice. (To check out more on the .xinitrc file, see my first installment of the Linux Desktop Invasion series.)

For new-school aficionados, there is yet another file you can edit to change your desktop. In the /etc/sysconfig directory, there is a file called desktop that contains a single line entry DESKTOP=”GNOME”. For a GNOME desktop, that line would look like: DESKTOP=”GNOME”. For a KDE desktop, that line would be:DESKTOP=”KDE”.

Once the file has been changed, log out of XFree86 (X) and log back in. Obviously, this method isn't exactly practical. Instead of having to open up and edit a file every time you want to change desktop environments, why not use a script? To automate this process, a simple bash script is all you need. This script will take input from the command line and echo that input to the ~/.xinitrc file. The script uses a case statement to select either GNOME or KDE, echoes that selection to .xinitrc, and then runs the startx command. Here's the script:
#! /bin/bash

case "$1" in

      echo 'exec gnome-session' > ~/.xinitrc

      echo 'exec gnome-session' > ~/.xinitrc

      echo 'startkde' > ~/.xinitrc

      echo 'startkde' > ~/.xinitrc

      echo $"chose either KDE or GNOME"
      exit 1



exit 0

I call this script switch. After the script is saved, I change its permissions with chmod u+x switch. At the command prompt (before X has started), I run the command ./switch gnome (or ./switch GNOME) to start GNOME and ./switch kde (or switch KDE) to start KDE.

The GUI method for changing desktop environments uses the Switchdesk GUI. When the switchdesk command is run, a small window will appear with five radio buttons. (The actual number will depend on how many desktop environments are installed on the machine.) Select the radio button next to the desired desktop environment, click OK, restart X, and the newly selected desktop environment will appear. The only problem with this method is that Switchdesk is created by Red Hat and is unique to Red Hat Linux, Yellow Dog Linux, and ASPLinux.

Disable the three-finger salute
A user’s ability to reboot a machine with the [Ctrl][Alt][Delete] key combination is a privilege than can be misused. To remove the possibility of “accidental” reboots, you can simply eliminate this functionality by commenting out the section:
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

To comment this out, add a # symbol before the ca:: and reboot the machine. The three-finger salute is now disabled.

That darn scroll wheel
When I have problems with a scroll mouse, the first item on my troubleshooting list is the XF86Config-4 file in /etc/X11. In this file, there is a section called InputDevice, and in this section there are three Options that are critical for the scroll wheel to work properly:
Option ''Protocol''       ''IMPS/2''
Option       ''ZAxisMapping''    ''4 5''
Option       ''Emulate3Buttons'' ''no''

Without the above options in place, the scroll wheel will not work properly.

The old cut-and-paste
I've been using Linux for so long that when I switch over to Windows, the cut-and-paste always trips me up. If you read between the lines, you’ll see that this means that there is, in fact, an easy way to cut and paste in Linux. So how do you do it? Open up a browser to your favorite site and then open up a console window with your favorite text editor. Highlight a section of text in the browser by clicking and holding the left mouse button. If you are using a three-button, or scroll-wheel, mouse, go to the console window and click the middle mouse button. Or, if you are using a two-button mouse, click both the left and right buttons at the same time. Viola, the test appears!

One aspect of the Linux desktop that clears the clutter from your desktop is a holdover from the Mac world. If you double-click on an active title bar, the entire window will shade. This means that the entire window disappears into the title bar, much like the old rolling window blinds of days gone by.

This little handy trick makes keeping your desktop neat and tidy a snap. In order to get the window back, just double-click on the title bar one more time.

Have any good desktop tips?
If you have any good Linux desktop tips you'd like to share, send them Jack's way! Or if you have a desktop problem that you can't figure out, send that to Jack as well, and he'll do everything he can to solve your desktop dilemma.


About Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.

Editor's Picks

Free Newsletters, In your Inbox