Chapter 2: Making Ubuntu Usable


The basic install of Ubuntu provides a usable system. But usable is not the same as optimal. When you first log into the system, there are some things that you will definitely want to change, like the colors (nobody likes brown-seriously, what can brown do for you?). This chapter discusses options for making the desktop and workspace environment more usable.

Logging in for the First Time

When you first log into Ubuntu, a few things will get your attention, like the login music. It's this increasing tone with twinkles that sound like an orchestra tuning up. And the desktop color scheme: brown. Before you can call the system usable, you will need to change these and other things.

Changing the Startup Music

The startup music is one of the easiest items to change. From the menu at the top, select System image from book Preferences image from book Sound. This brings up the Sound Preferences applet (see Figure 2-1). From here, you can assign sounds to system events. For example, I have a blood-curdling scream for error messages, and a telephone ringing for question dialog boxes.

image from book
Figure 2-1: The Sound Preferences applet

Warning 

New sound selections are not always used immediately. If you find that your new sounds are not immediately used, log out and log back in. This seems to be a bug in the Gnome Sound Preferences applet.

Converting Audio Files

You may select any WAV audio file for any of the audio events. If you want to use a different audio format, such as MP3 or OGG, you will need to convert it to a WAV file. The easiest way to convert audio files is with sox-the universal sound exchanger.

  1. The sox package comes from the universe repository, but this repository is not enabled by default. As root, you will need to edit /etc/apt/sources.list and uncomment the two universe lines. These should be near the top of the file and look similar to:

     deb http://us.archive.ubuntu.com/ubuntu/ dapper universe deb-src http://us.archive.ubuntu.com/ubuntu/ dapper universe 

    You will also need to update the repository cache:

     sudo apt-get update 
    Note 

    The /etc/apt/sources.list file and the apt-get process are detailed in Chapter 4.

  2. Install sox if it is not already installed.

     sudo apt-get install sox 
  3. Use sox to convert the audio file. By default, sox determines file types by the file extension.

     sox fileIN.mp3 fileOUT.wav 
  4. Test the sound file using the play command.

     play fileOUT.wav 
  5. From the Sound Preferences applet, select the pull-down menu for the desired system sound, for example, Log in and click Select sounds file

  6. Select the WAV file you just created.

Note 

Although sox comes from the universe repository, lame comes from the multiverse repository. You will need to uncomment the multiverse lines in /etc/apt/sources.list and run sudo apt-get update before you can install it. See Chapter 4 for more details.

image from book
SOX Ain't LAME

The sox application is a great tool for converting and modifying sound files, but it does not support all formats for all functions. In particular, even though it can read MP3 files, it cannot be used to create MP3 files without additional libraries. To resolve this constraint, you can use lame package to encode MP3 files from WAV files.

Just as GNU is a recursive acronym "GNU is Not Unix", LAME uses a recursive name: LAME Ain't an MP3 Encoder. Ignoring the name, lame is a powerful tool for creating MP3 files. First, make sure the package is installed: sudo apt-get install lame. Then, convert your WAV file to an MP3 file: lame fileIN.wav fileOUT.mp3.

The MP3 file from LAME cannot be used for system sounds (because system sounds do not support MP3 files) but can be used by other audio applications and portable music devices.

image from book

Modifying Audio Files

Most WAV files are larger than a few seconds, and you probably do not want a three-minute song playing every time you click a button. The sox program can be used to trim audio files, but you will need to know the starting time for the sound you want and the length. For example, to start 3 seconds into the file and keep a 2.31 second duration, use:

 sox fileIN.mp3 fileOUT.wav trim 3 2.31 

Trim times can be written in a variety of formats. You can specify seconds (and fractions of a second) or actual time values. The value 125.6 can be written as 2:05.6 or 0:2:5.6. The notations indicate seconds (with fractions), minutes, and hours. Also, if you do not specify the duration, then it goes to the end of the file.

The sox command can also add effects such as echos, high-pass and low-pass filtering, stretching, and reversing. For a full list of functions, refer to the sox man page (man sox).

Changing the Background

The default background for Ubuntu Dapper Drake is a brown screen with a bright highlight. As my fashionable coworker tells me, "Nobody likes brown." So the background must be changed. The System image from book Preferences image from book Desktop Background menu item brings up the Desktop Background Preferences applet.

Tip 

You can also bring up the Desktop Background Preferences applet by right-clicking the desktop background and selecting Change Desktop Background from the popup menu.

Although Ubuntu does include some very colorful backgrounds, you can always add your own. Unlike the Sound Preferences, where you are limited to one type of audio file format, the desktop supports many graphic formats. GIF, JPEG, BMP, PCX, TIF, and PNG are all acceptable formats. Besides selecting an alternate image, you can also select whether the image should be tiled, stretched, or centered, or have a border color. In Figure 2-2, I selected my Safe Computing logo, centered, with a vertical gradient background. Since my image is a GIF with a transparent background, the desktop's color scheme blends well with the picture.

image from book
Figure 2-2: The Hacker Factor Safe-Computing logo as a background with a gradient color

Note 

Even though the desktop supports many different graphical formats, there are some graphics that it does not support. In particular, the desktop background displays static pictures. Animated GIFs are not animated, MPEG videos do not work as backgrounds, nor do Adobe Flash movies. In Chapter 9, you'll see how to create animated backgrounds.

Tip 

If you need to crop or modify your picture, the Dapper Desktop installation automatically includes Gimp, a powerful graphics editor.

Changing the Background As-Needed

The picture and color on the desktop does not need to be static. You can write a simple program to change the picture (or color) as needed. The basic commands are:

 gconftool-2 -t str --set /desktop/gnome/background/picture_filename \     /path/picture.gif gconftool-2 -t str --set /desktop/gnome/background/primary_color "#AABBCC" gconftool-2 -t str --set /desktop/gnome/background/secondary_color "#112233" 

The Gnome Desktop Manager (GDM) keeps a set of configuration parameters, similar to the Microsoft Windows registry. Although the gconf-editor command enables you to interactively view and edit the values (similar to the Windows regedit command), and the gconftool-2 command enables you to edit values from the command line. Within the registry, the picture_filename field stores the name of the background image (in this example, /path/picture.gif). Be sure to specify the full path to the image. As soon as you change the image in the registry, the image on the background changes.

Similar to picture_filename, the primary_color and secondary_color fields are used to control the background color. If you only have a solid background, then the color is defined by primary_color. The secondary_color is only used with a color gradient. Colors are represented by three hex bytes that denote red, green, and blue. Black is #000000, white is #FFFFFF, and a nice light blue is #2255FF. As with the background image, as soon as you change the color in the registry, the color on the background changes.

Using Informative Colors

The background color does not need to be a static color. You can create a script to change the color based on system events. For example, you can monitor a log file and change the background to red when something serious happens. To give you an example, Listing 2-1 is a simple Perl script that changes the background color to represent the system load.

Note 

The results from the script in Listing 2-1 will only be visible if you have some portion of the desktop background displaying the primary background color. If you have a graphic that covers the whole desktop, then you will not see anything.

Listing 2-1: Script to Change Background Color with Load

image from book
     #!/usr/bin/perl     # Color the background based on system load     my $Key = "/desktop/gnome/background/primary_color";     my $Load; # system load     my $R, $G, $B; # Red, Green, Blue colors     while ( 1 )       {       $Load='uptime'; # get the current load       # format is "time duration, users, load average: 0.00, 0.00, 0.00"       # remove everything except the first load value       $Load =~ s/.*: //;       # load values: 1 minute, 5 minute, 15 minute averages       # these are colored: 1=Red, 5=Green, 15=Blue       ($R,$G,$B) = split(', ',$Load);       # scale up to the range 0-255, but cap it at 255       $R = $R * 255; if ($R > 255) { $R = 255; }       $G = $G * 255; if ($G > 255) { $G = 255; }       $B = $B * 255; if ($B > 255) { $B = 255; }       # convert to hex       $Load = sprintf "%02X%02X%02X",$R,$G,$B;       # set the color       system("gconftool-2 -t str --set $Key '#$Load'");       sleep 15; # Update 4 times per minute       }     done 
image from book

This script will change the background color every 15 seconds based on the system load. A reddish color indicates that the system is very active. Yellow indicates an active process that has been running at least 5 minutes; white means at least 15 minutes. If no processes are raising the system load, then the colors will cycle from green to blue to black. If you want to know when the system is busy, a sudden change in the background color should get your attention.

Changing the Fonts

The default font for the Ubuntu desktop is Sans at 10pt. You can change the font used by the desktop through the System image from book Preferences image from book Font applet. Changing the fonts immediately changes what is displayed on the desktop.

Changing the DPI

Different output devices render the fonts at different resolutions. Increasing the font size will make it appear larger on all devices including the screen and printer. On the other hand, if you change the rendering resolution for a single device, then the same font size appears different.

The default desktop fonts are rendered at 96 dots per inch (dpi). You can change the dpi value by opening the System image from book Preferences image from book Font applet and clicking the Details button.

Although the Font applet is good for one-time changes, it cannot be easily automated. The dpi value can also be set through the gconf-edit registry under /desktop/gnome/font_ rendering/dpi. This value can be adjusted to match your screen. For example, a monitor that is 14 inches across at 1024×768 has approximately 73 horizontal pixels per inch, while a 20-inch wide screen at the same resolution has 51 pixels per inch. The default desktop assumes 1024×768, with 10 inches across. If you change the screen resolution or use a different size monitor, then fonts may appear larger or smaller.

To change the dpi value, use:

 gconftool-2 -t float --set /desktop/gnome/font_rendering/dpi 96 

Values larger than 96 will make the fonts appear larger (but not change the actual font size), whereas a smaller number decreases the rendered size. In general, changing the dpi setting only changes how fonts are rendered on the screen. It does not change the size of the application windows nor impact how documents will print.

Helping with Big Fonts

I have a couple of co-workers who wear reading glasses when sitting at the computer. More than once, they have come over to my work area and had to run back to get their glasses. To help them (and tease them), I created a Grandpa Mode macro that increases the screen font size-just for them. Permanently setting up the ability to use Grandpa Mode as desired requires four commands. The first two define custom commands that change the dpi value. The second two bind the commands to key sequences.

 gconftool-2 -t str --set /apps/metacity/keybinding_commands/command_7 \   'gconftool-2 -t float --set /desktop/gnome/font_rendering/dpi 200' gconftool-2 -t str --set /apps/metacity/keybinding_commands/command_8 \   'gconftool-2 -t float --set /desktop/gnome/font_rendering/dpi 96' gconftool-2 -t str --set /apps/metacity/global_keybindings/run_command_7 \   '<Control>F7' gconftool-2 -t str --set /apps/metacity/global_keybindings/run_command_8 \   '<Control>F8' 

Now pressing Ctrl+F7 changes the resolution to 200 dpi and make the fonts appear large (and coworkers can read it without glasses). Ctrl+F8 returns the screen to the system default of 96 dpi (see Figure 2-3).

image from book
Figure 2-3: The desktop and Gnome terminal as seen at 96 dpi (left) and 200 dpi (right). Both are taken on the same 1280×1024 monitor.

Note 

Changing the rendering resolution only alters fonts rendered by the desktop. For example, the Gnome terminal (Applications image from book Accessories image from book Terminal) changes size, but an xterm window will not. Also, some applications, such as xchat, use hard-coded window heights, so the tops or bottoms of large fonts may get cut off.

If you want to remove Grandpa Mode, you can use the gconftool-2 –unset option:

 # reset default dpi gconftool-2 -t float --set /desktop/gnome/font_rendering/dpi 96 # unset key mappings gconftool-2 --unset /apps/metacity/keybinding_commands/command_7 gconftool-2 --unset /apps/metacity/keybinding_commands/command_8 gconftool-2 --unset /apps/metacity/global_keybindings/run_command_7 gconftool-2 --unset /apps/metacity/global_keybindings/run_command_8 

Tuning the Shell

Most of these Ubuntu hacks require you to use the command line and that means using the GNU Bourne-Again Shell (bash). Bash has replaced shells such as sh, csh, and tcsh on most Linux distributions. When you open up a command prompt or terminal window, the default shell is bash. Bash uses the same syntax as the original Bourne Shell (sh) but has many more features for usability. For example, the up and down arrows can be used to scroll through the shell history.

Bash also enables you to edit command lines in either vi or emacs mode.

 set -o vi    # enable vi-mode set -o emacs # enable emacs-mode 

The default edit mode under Ubuntu is emacs. If you want to specify the mode (rather than inherit default settings), then add the appropriate set command to the end of your .bashrc file. This way, it will be set whenever you log in or open a new terminal window.

Tip 

You can tell if Bash is using vi or emacs mode by running set -o (with no other options) or with echo $SHELLOPTS.

You may also want to change the default editor for applications by adding one of these lines to your $HOME/.bashrc file:

 export EDITOR=vi    # enable vi-mode export EDITOR=emacs # enable emacs-mode 

After modifying your $HOME/.bashrc file, you can reload it using: . $HOME/.bashrc. This is called dotting in because the command you are running is a single dot.

Completing Completion

Bash includes file completion so you don't need to type in very long file names. Pressing the Tab key fills out a partial file name with the available files. Pressing Tab twice lists the available files. For example, ls a<TAB> will complete the file name if there is only one file beginning with the letter a. And ls a<TAB><TAB> lists all files beginning with a. In these examples, if you do both <TAB> and <TAB><TAB> and see no file completion, then you have no file names that start with a.

image from book
Shell Games

There are a few topics in the computer field that can start passionate arguments on the scale of religious wars. The first topic is "Windows or Unix". Both sides have zealots who are willing to argue this topic to the death. (And anyone who is thinking "What about Macs?" knows the depth of this debate.) Even among Unix users, "Linux versus BSD" can spark heated debates. One of the most violent topics comes from the choice of editors. "Emacs vs. vi" can lead to real bloody battles.

When you need to help someone else at his terminal, it is a common courtesy to ask before switching modes. A vi user who finds himself in emacs mode can become very miffed. Instead, consider creating a subshell while you work. Running bash -o vi or bash -o emacs will open a shell in your favorite mode. Now you can change directories, set aliases, or edit the command line without interfering with the system's owner. When you're done, just exit and the shell closes. This leaves the owner's terminal unchanged.

image from book

Under Dapper Drake, the default .bashrc loads the file /etc/bash_completion. This file contains many other completion settings. For example, there is a special completion sequence for the command apt-get. Typing apt-get up<TAB><TAB> displays update and upgrade since those are the available options. This default file (/etc/bash_completion) contains options for many widely used commands.

Note 

Older versions of Ubuntu, such as Hoary and Breezy, have the file /etc/bash_completion on the system, but it is not loaded by default. The default .bashrc contains some commented- out lines for loading the completion file.

Awesome Aliases

Aliases are simple shortcuts for commonly typed commands. Usually people add aliases for the ls command to their .bashrc file. For example:

 alias l.='ls -d .[a-zA-Z]*'   # list all system files alias ll='ls -l --color=tty'  # list using "ls -l" alias llf='ls -l --full-time' # list using the full timestamp alias ls='ls -F' # make ls display the file type 

Tip 

If you don't want to use the command alias then preface the command with a backslash. For example ls uses the ls -F alias, but \ls will just run the regular command.

There are a couple of other aliases that I find useful. The first is telco. The telco alias enables me to quickly look up phone numbers. Simply give it the area code and prefix for a phone number in North America and it will provide you with the city, state, and rate center. This is a useful command when you begin to wonder, "What city has phone numbers that begin with 781-202?" (Burlington, Massachusetts).

 $ alias telco='whois -h whois.telcodata.us' $ telco 781-202 Telcodata.US Whois Server -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Your command was: 781-202 Data for 781 - 202 follows: Area-code:      781 Exchange:       202 State:          MA Company:        ACC NATIONAL TELECOM CORPORATION - MA Type:           CLEC Ratecenter:     BURLINGTON Switchtype:     WECO 5ESS Host (Digital) CLLI:           BSTNMACODS2 
Warning 

The telco alias logs your IP address. If you use it too often, then you will receive a warning about too much usage. The kind people who run whois.telcodata.us do not want you to abuse their service.

Another alias that I use often is pinger. This alias simply displays a number every five seconds. Many firewalls assume that no traffic after a while indicates a closed connection. If I know I will be walking away from a live connection, I run the pinger alias just to generate traffic and keep the connection alive.

 alias pinger='(i=0; while [ 1 ] ; do sleep 5 ; echo $i; ((i=$i+1)); done)' 

Fun Functions

Besides storing aliases, the .bashrc file can store shell functions that can be used in place of commands. For example, pinger can also be written in the .bashrc file as:

 function pinger() { i=0; while [ 1 ] ; do sleep 5 ; echo $i; ((i=$i+1)); done } 

Another function that I use is ccd:

 function ccd() {   if [ "$1" == "" ] ; then     echo "Usage: ccd location"   elif [ -d "$1" ] ; then     # if it is a directory, go there     cd "$1"   else # must not be a directory     # Cut off filename and cd to containing directory     cd "${1%/*}"   fi } 

The ccd function works similar to the cd command, except that it does not mind when you paste a line containing a file name. For example, cd ˜/public_html/logo.gif will fail because the target must be a directory. But ccd ˜/public_html/logo.gif will see that logo.gif is a file and place you in the same directory as the file.

Cool Commands

There are two other lesser-known features of Bash. Ctrl+T transposes the last two characters at the cursor. This way, the common typing error sl can be quickly corrected to ls. For other lesser-known Bash commands, see the Bash man page (man bash).

The other is the CDPATH environment variable. The PATH environment variable specifies where to look for commands. This usually looks something like:

 export set PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games 

When you run a command, the shell first checks if the program exists in /usr/local/bin, then in /usr/sbin, and then /usr/bin, and so on until it is found. The CDPATH variable tells cd where to look when the directory is not in your current directory. For example:

 export set CDPATH=.:~:/usr:/etc 

If you type cd bin, then the shell will first check for ./bin. If that does not exist, then it will try ˜/bin followed by /usr/bin and /etc/bin. This can come in really handy if you find yourself frequently trying to type cd public_html (or some other directory) when you're in the wrong location.



Hacking Ubuntu
Hacking Ubuntu: Serious Hacks Mods and Customizations (ExtremeTech)
ISBN: 047010872X
EAN: 2147483647
Year: 2004
Pages: 124
Authors: Neal Krawetz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net