• Tip Jar

Console Keyboard Shortcuts

People have been asking about keyboard shortcuts from the console. They do exist, and are very powerful. To create the shortcuts, you need to edit your ~/.inputrc file. These shortcuts are available in the terminal, not in applications. So, your shortcut won’t work inside Linphone for example. The following is a setup that will create keyboard shortcuts for the musicl player XMMS2, including a soft volume control, so your whole computer doesn’t drop or rise in volume with the music. Before using the volume controls you need to enter this in your terminal:

nyxmms2 server config effect.order.0 equalizer
nyxmms2 server config equalizer.enabled 1

You may notice that each of the following shortcuts end with \C-M. This is what appends a new line to the command, it’s the same as pressing enter when you’re done typing. Without it, the command would just sit there, looking all purdy, but not really doing anything. And now, here are the lines you can add to your ~/.inputrc for XMMS2 controls:

"\ez":"nyxmms2 prev&&sleep 0.5&&nyxmms2 current\C-M"
"\ex":"nyxmms2 play&&nyxmms2 current\C-M"
"\ec":"nyxmms2 toggle&&nyxmms2 current\C-M"
"\ev":"nyxmms2 stop\C-M"
"\eb":"nyxmms2 next&&sleep 0.5&&nyxmms2 current\C-M"
"\e-":"nyxmms2 server config equalizer.preamp $(($(nyxmms2 server config equalizer.preamp | tr -Cd \"[:digit:]-\") - 5))\C-M"
"\e=":"nyxmms2 server config equalizer.preamp $(($(nyxmms2 server config equalizer.preamp | tr -Cd \"[:digit:]-\") + 5))\C-M"

As you can see, the format is "key":"command". The \e means to use alt as a modifier. Here is a nifty little table that shows the keybindings for the code above.

Key Action
Alt+z previous track
Alt+x play
Alt+c pause
Alt+v stop
Alt+b next track
Alt+- volume down
Alt+- volume up

If you want to use the control key in your keyboard shortcut, simply replace \e\C like so:

"\C-t":"\C-k \C-utalking-clock -c &> /dev/null\n" #speak time control+t

And there you have it, keyboard shortcuts in the console. These are very useful, I have a lot of them in my ~/.inputrc and use most of them every day.

Sharing the Clipboard with the Console

Sharing the clipboard between your GUI desktop and the console can be a bit of a challenge. I was doing it by pasting into a temperary file then opening that file in the console. Then, however, I got to thinking there has to be a better way. So, I wrote a bit of code in python to automatically check the clipboard for text and write it to /tmp/clipboard. It works quite nicely, but I have noticed that when it is running, switching between applications with alt+tab is slower than normal. It may be something to do with the loop slowing things down, but I am not sure. For those who are interested, here is the code:
#Clipboard to File Written by Storm Dragon
#Copyright May 2011 by Storm Dragon
#License GPL
#This program places any text in the clipboard into the file /tmp/clipboard
#The file is updated every 0.5 seconds

#Library import section
import time
import pygtk
import gtk
#Loop forever!
while True:
    #Get the clipboard
    cb = gtk.clipboard_get()
    #assign the clipboard contents to a variable.
    cbText = cb.wait_for_text()
    if isinstance(cbText, str) == True:
        file = open(“/tmp/clipboard”,”w”)
After I completed this small program I learned of the existance of a clipboard manager called parcellite. In Ubuntu and Vinux you can install it with:
sudo apt-get install parcellite
You can adjust parcellite’s preferences by right clicking on it in the panel and selecting preferences. If you left click it you will get the clipboard’s contents and the history up to 100 previous selections depending on the setting in preferences. You can also access the clipboard history with the keyboard shortcut control+alt+h. In order to have parcellite start when you login, you will need to add it to startup applications in System, Preferences, Startup Applications. If you choose to use my script you can add it to startup applications instead.
If you use parcellite you can access the clipboard history in the console in the file located at:
Because it is a binary file it does not work in Gedit.
If you use my program or the clipboard manager glipper it will work in gedit. The file my program writes to is:
My program does not contain any history, only the last text in the clipboard.
After a bit more research I find I prefer using the clipboard manager Glipper:
sudo apt-get install glipper
To access the clipboard press control+alt+c. To access the history in the consolesimply open the file:
Of course, if you use glipper you do not need my script.
Parcellite also has the ability to copy text from the terminal, gnome-terminal or any terminal opened from the desktop. If you try from the console you get an error about not being able to open the display. If you do:
echo “hello world” | parcellite
then the words "hello world" will be in your clipboard. You can accomplish the same thing by using a program called xclip:
sudo apt-get install xclip
To place something in the clipboard:
echo “hello world” | xclip -selection clipboard
You can download Clipboard to File by right clicking the link and selecting save link as.
After some descussion it was decided that probably the best way to cut out the lag caused by clipboard-to-file is to drop the loop completely and just bind the program to a keyboard shortcut. So, here is the new code, the download link will now also get you this code as well:
#Clipboard to File Written by Storm Dragon
#Copyright May 2011 by Storm Dragon
#License GPL
#This program places any text in the clipboard into the file /tmp/clipboard

#Library import section
import time
import pygtk
import gtk
#Get the clipboard
cb = gtk.clipboard_get()
#assign the clipboard contents to a variable.
cbText = cb.wait_for_text()
if isinstance(cbText, str) == True:
    file = open(“/tmp/clipboard”,”w”)
I went to System, Preferences, Keyboard Shortcuts and added clipboard-to-file and set its shortcut to control+alt+v. This new method has all of the coolness with none of the slowness.
One more thing that will make sharing info between the GUI desktop and the console easier is a paste command for the IRC client irssi. I actually have 2 of them. These use assume you are using glipper. The first simply pastes the last thing in your clipboard history to irssi and sends it as a message:
/alias paste /exec -o cat /home/USER/.glipper/history | head -n 2 | tail -n 1
the other is for when you want to paste several lines. Each line will be sent as a message so be careful with this one. Irssi will prompt you if you try to send more than seven lines, so there is a safety net:
/alias read /exec -o cat /tmp/clipboard
To use this one just make sure the text you wanto to send as a message is in the file /tmp/clipboard.

Commanding the Command Line (Part 2)

This is part two of a discussion of accomplishing your hearts desire with out the use of a GUI. It’s back to the console for us as we dive in to such fun things as web browsing, instant messaging, and text editing.

Instant Messaging with Finch

Pidgin and Finch are closely connected. finch is the command line version of Pidgin. So, the way I handle setting up accounts is with Pidgin. Then, in the console launch by typing finch. The first time you run it you will be presented with the accounts list. Use highlight tracking in Speakup because it works better with Finch. Press space on each account you want activated. Move through them with the up and down arrow keys. When you activate an account it will say X to show that it is checked. When you have activated all of your accounts, press alt+a to be taken in to a menu with items like buddy list, plugins, sounds, etc. Select the sound option and tab until you find the first sound option, probably "Someone says your name in chat". Press space to check each item for which you would like to have sound. Use the up and down arrows to navigate the list. After selecting the sounds you want, press alt+a to get back to the menu. I must say that I have never successfully gotten sounds to work in Finch but I know people who have, so it’s just my problem apparently. Select Plugins and check the plugins you would like to activate. Most of the plugins that work in Pidgin also work in Finch. This is a good time to mention my favorite sets of plugins. Some of these only work with Pidgin, but I will include them anyway. Pidgin-musictracker displays your currently playing track in Pidgin. Pidgin-plugin-pack, lots and lots of useful plugins. Pidgin-mbpurple, adds Twitter and a couple of other things to Pidgin. To get them all:
sudo apt-get install pidgin-plugin-pack pidgin-musictracker pidgin-mbpurple
When you have the plugins configured the way you want them, press alt+a to get back to the menu. If you are not on your list of groups that contain your contacts, press tab until you get to it. Only buddies who are on-line will show up. To expand a group press space and to close it press space again on the group title. If you press f10 you will get another menu with things like add buddy in it. If you would like to turn off time stamps, while chatting with someone press f10 and press enter on show time stamps. To exit Finch press alt+q.

Web Browsing with Elinks

To get elinks, in Ubuntu, type:
sudo apt-get install elinks
When you first install Elinks, it takes some configuring to get it working optimally with Speakup or any other console screen reader. To launch it type:
If it is the first time you will get a welcome message. Press enter to go to the next screen. Here it will ask for a URL. Press escape to get into its menus. In Speakup, it is a good idea to turn on highlight tracking if you haven’t already. Press right arrow to get to the Setup menu, then down to Options Manager and press space to activate it

Numbered Links

Move down to Document and press space to activate it then down to browsing and press space again. Go down to links and press space. Move down through the menu until you find Numbered Links and press tab until you get to Edit then press enter. For some reason these selections do not read exactly right. when I was on the Edit option, for example, it said "Info Edit". Press backspace to remove the 0 and type the number 1 in its place and press enter. Now links on pages will be numbered. To activate a numbered link type its number and press enter then enter again to activate it.

Turn Off Frames

Press down arrow until you get to Html Rendering and press space. Go down to Show Frames and tab to the Edit option and press enter. Change the 1 to 0 and press enter.

Remember to Save

When you have finished setting options, be sure to save. Tab until you get to the save option and press enter. In this case, Speakup read it as "Search Save". You will know you did it right if you get a message about the configuration being written successfully.

Tips and Tricks

You can launch elinks with an address so when it opens you will go directly to a web page instead of having to type in the address. for example:
elinks http://www.stormdragon.tk/
elinks stormdragon.tk
To enter a new URL press g. If you would like to be able to copy the current URL, press shift G. You can use screen’s excellent copy feature to get the current address.

Email with Alpine

To get Alpine, in Ubuntu, type:
sudo apt-get install alpine
To launch Alpine type:
the first time it runs it will create a mail folder and show you a welcome message. Press enter to get to the main menu, then s for setup and c for configure. If you want to use Alpine with your gmail account, there is an excellent guide that shows you how. If you get imap errors when trying to retrieve your email, open the .pinerc file and search for the line that reads:
Remove any extra characters after the right brace } and save the file. It should now work correctly. Alpine works very well with Speakup and the menus are clear and not difficult to follow.

Commanding the Command Line (Part 1)

In the event that you decide to, or for some reason have to go completely command line for a while, you will likely be wondering how to do certain things. There are some things that have to be done on any computer to make the computer in question worth it’s plastic. So, here is part one of a discussion on doing these important tasks from the command line. Some of this may be covered elsewhere here but I am including it again for the sake of completeness. To get to the console from gnome, press control+alt+f1 through f6. You have six consoles to choose from, but when you wanna go back to gnome, it is control+alt+f7. If you want to use the console you will need a screen reader for it like Speakup. For information on installing Speakup in Ubuntu read "Speakup Revisited".
If you are completely new to the command line, you can use these two tutorials to get started with it quickly:
Into the Linux Command Line Interface (CLI) and Introduction to Command Line Interface (CLI) 2.

Multiple Terminals With Screen

I am pretty sure that Ubuntu comes with screen installed. I don’t ever remember installing it, but it could have sneaked in as a dependency for something else though I doubt it. If you don’t have screen, you need it. To launch it, type screen. You will have to press enter after it starts to get your prompt back. Screen makes it so you can have several terminals all at once. To create a new one, press control+a followed by c. You can have as many as you want, one for music, one for email, one for instant messaging, etc. To switch between terminals, press control+a followed by n for the next one or p for the previous one. To close a terminal that you no longer need, type exit. Another great feature that screen has is the ability to copy and paste. When you need to copy something, press control+a followed by either the escape key or [. Use the arrow keys to position the cursor on the first of the text you would like to copy and press space. Find the last part you want to copy and position the cursor on it with the arrow keys and press space again. Now, when you need to past the copied information press control+a followed by the ] key.
The use of a ~/.screenrc file can help Orca users to copy from the terminal. Installing xclip is helpful for this. To get it:
sudo apt-get install xclip
Here is the .screenrc file that I use:
#Begin .screenrc
startup_message off
defscrollback 1024
bind b eval "writebuf" 'exec !!! xclip -selection "clipboard" -i /tmp/screen-exchange'
termcapinfo xterm|xterms|xs|rxvt ti@:te@
#end .screenrc
If you want to download this file, enter the following command in terminal:
wget -O ~/.screenrc http://stormdragon.tk/scripts/screenrc
Using this .screenrc file you can press control+a b after following the above instructions to copy text to place the copied text into the clipboard. If you are using screen in the console where the X clipboard is not available, you can still easily get the copied information from the file:
To move up and down through the terminal’s buffer press shift+pageup and shift+pagedown. This is slightly different from gnome-terminal with out screen in which you press control+shift+pageup and control+shift+pagedown to move through the buffer.

Twitter From The Command Line

The program twidge is an excellent command line Twitter client. A lot of distros include it in the repositories. In Ubuntu, for example, you can get it by typing in terminal:
sudo apt-get install twidge
If your distro doesn’t include it you can download it from http://software.complete.org/software/projects/show/twidge.
After installing Twidge, you need to configure it. To do this, type:
twidge setup
There are only two questions and they should be very easy to answer. After twidge is configured, you can get the latest tweets very easily. First though, you should run:
twidge lsrecent -su
This gets the last 20 tweets and also sets a place marker so you won’t see them or anything before them if you do not wish to do so. After running this command, you can then get all new tweets by typing:
twidge lsrecent -asu
To post an update type twidge update and press enter. Type your update and press enter again, just remember not to go over the 140 character limit. For more detailed instructions on Twidge and its uses, type:
man twidge
You may also be interested in TTYtter.

Weather Information

I wrote an article on weather a while ago. There is a great program called weather-util for the console. To find out how to install and configure it, please read "…And Weather For All".

Command Line Music Player

I have tried several terminal based music players. None of them worked well with Speakup. I was about to lose hope in ever finding a good one to use with a screen reader when I heard of cmus. In Ubuntu, get it by typing:
sudo apt-get install cmus
Launch it with the command:
and close by typing:
After the first time you start and close the music player open the ~/.cmus/autosave file. Find the line that reads:
set softvol=false
Change it to true and save the file. softvol allows you to change the music players volume without changing volume for the whole computer. There are a lot of other settings that can be changed in this file including repeat and shuffle. To add music to the library use :add and the directory where the music is stored. You can use :a as a short cut if you prefer. To add all of the songs in ~/Music and its sub directories, for example, you would type:
:a ~/Music
Use – to decrease the volume and = to turn it up. Previous track is z, play is x, pause is c, stop is v, and next track is b. Use the up and down arrows to move through the tracks in your library and enter to play the currently selected song.. For more info on cmus, type man cmus.

Sox, the Swiss Army Knife of Sound Processing Utilities

Sox is one of my favorite command line programs. It can play audio, record, convert from one file type to another, and add effects to audio. Unfortunately it is not packaged with all of its powerful abilities enabled by default. The best way to deal with this little problem is to download and install it yourself. The only thing it is lacking is the ability to write mp3 files. It can play them, but by default, in Ubuntu and I assume other distros, it can not write mp3 files. So, if you do not care about this functionality, just do the normal sudo apt-get install sox. If you want to be able to convert to mp3, you will need to download it from http://sourceforge.net/projects/sox/ and install it. Before installing though, you will need to get some other libraries. In Ubuntu type:
sudo apt-get install libmp3lame0 libmp3lame-dev libsox-fmt-all
sudo apt-get build-dep sox
Next extract the sox files with the following command. The version may have changed after this writing, so be sure to use the current numbers in the file name:
tar xzvf sox-14.3.0.tar.gz
Change to the newly created directory with:
cd sox-14.3.0/
./configure --with-lame
sudo make install
For more information on the options that can be used when compiling sox read the included INSTALL file.
Sox can do so many different things that it would take a long time to write them all down here. Here are a few things to get you started though:
sox filename.wav filename.ogg
Convert filename from a wav to an ogg file. Don’t worry, it doesn’t delete the wav file. You can convert from any type to any other type of audio.
play filename.ogg
Plays a file it can have effects added and the volume can be adjusted as well.
rec filename.ogg
Creates a file and starts recording to it. for all of the incredible things sox can do, type man sox.

  • Tip Jar