Results 1 to 10 of 25

Thread: HOWTO: Get a useful text-based desktop (embedded terminal plus conky)

Threaded View

  1. #1
    Join Date
    Sep 2006
    Location
    Denmark
    Beans
    202
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    HOWTO: Get a useful text-based desktop (embedded terminal plus conky)

    This howto will explain how to go about turning your desktop into a useful text-based interface with input (an embedded terminal always on top the desktop of every workspace) and output (simple, useful and unobtrusive alerts about unread mail, music playing, downloads finished etc.). Using the desktop as a text interface is convenient, unobtrusive and has a nice retro-tiling-window-manager charm

    Some of this ground is covered in other howtos. Apart from gathering the information and adding new bits, this will focus on being fairly minimalist (in keeping with the overall theme), using lightweight, single-purpose apps. No Compiz-Fusion required.

    Please note: Especially the conky part of this howto supposes a modicum of familiarity with shell scripts, i.e. knowing what a 'shell script' is, what file permissions are (and how to change them), and how to execute scripts (by using and modifying the $PATH variable or writing out the absolute path of the script). If all this is completely foreign to you, you might want to reconsider if this is for you, or if you're interested in learning, check out this excellent tutorial at linuxcommand.org. Ten minutes well spent, I promise.



    Embedded terminal
    This will use the XFCE4 terminal (GNOME users can install - sudo apt-get install xfce4-terminal - it is fairly lightweight - or check out this thread)

    Most of the necessary settings to run the native xfce4 terminal as an 'embedded' terminal (i.e. dropping borders and bars and stuff) can be set at the command line when running it. Some can't, so enter the terminal preferences ( Edit | Preferences ) and disable scrollbars in the General section (Scrollbar is: disabled). In the Appearance section, choose 'Transparent backround' and turn the shade slider down to none. These settings will also affect 'normal' terminals (as long as you use xfce4-terminal for 'normal' sessions) but it will not render it unusable, just a little odd.

    Now when we run the terminal with the command line:
    Code:
    xfce4-terminal --hide-menubar --hide-borders --hide-toolbars
    we'll have a free-floating terminal.

    However, we still need for the terminal a) to occupy a specfic portion of the screen, b) appear below all other windows on every workspace and c) not appear in the tasklist or the pager (the one showing a small representation of your workspaces) in order to properly call it embedded. For this we'll use a little tool called wmctrl (devilspie as recommended by some other howtos is pretty cumbersome, needs to be loaded beforehand and has horrible documentation). wmctrl will identify your new terminal window and add all the abovementioned qualities to it. Install wmctrl:
    Code:
    sudo apt-get install wmctrl
    Here I've put it all in a small script that starts the terminal and adjusts it in one fell swoop (if you're unfamiliar with the syntax, the &&'s wait for the former command to exit succesfully before starting the next command):

    Code:
    #! /bin/bash
    
    xfce4-terminal --hide-menubar --hide-borders --hide-toolbars --title=descon && wmctrl -r descon -e 0,10,10,720,720 && wmctrl -r descon -b add,sticky,below && wmctrl -r descon -b add,skip_pager,skip_taskbar
    First xfce4-terminal starts a stripped terminal with the title descon. wmctrl then runs with various arguments: "-r descon" identifies the window, we've just named, to be targeted. The "-e [numbers]" is the geometry bit, i.e. where should the window be placed and how big should it be. 0 is for 'gravity' (can be disregarded for the purposes of this howto - just leave it at 0). 10,10 is for upper left corner coordinates, i.e. how far from the top left corner of the screen should the top left corner of the window be. 720,720 is for the width and height of the window (in that order). "-b [action],[property]" tells wmctrl to change the specified properties of the window targeted. In this case we tell it to add the sticky quality (reappering on all workspaces), and the below quality (stays below other windows even when focused), and tell it not to show up in the pager (showing workspaces) or the taskbar. If you want to know more about wmctrl and what it can do, it has a very good MAN page (type 'man wmctrl' at the command line).

    Edit the script above to your liking, e.g. change the size of the window to fit your screen and your taste. Save it, e.g. in a 'scripts' directory in your home directory, and make it executable ( chmod a+x [name of script] ).

    Test that it works by starting a "Run program" window (Alt+F2 on most systems) and enter the following command:
    Code:
    xfce4-terminal -x [location and name of script, e.g. /usr/local/bin/descon]
    (Note: we run a shortlived terminal which fires off our script - dont't ask why, this just appears to be necessary)
    After a short flickering you should have a terminal on your desktop.

    Now, we're going to add it to 'Autostarted applications' (XFCE-specific; GNOME users: it's probably something with autostart, sessions or startup). Click Add, type in a name and a description and enter "xfce4-terminal -x [location and name of script]" in the 'Command:' line. Click 'Ok' and close the Autostarted applications (making sure that your new app is ticked).

    Please note that if you're using session saving (this has only been tested on XFCE4 but I assume that it applies to any kind of session saving) that you should NOT save a session with the embedded terminal running as the saved session info does not include the properties that wmctrl adds to the window, i.e. below, skip_pager, etc.

    Text-alerts
    I tend to keep the terminal in the left hand side of the desktop, reserving the right hand side for these handy little notifications. As opposed to popups and the like, these do not make a big noise and a splash but will be easily decipherable when you (happen to) glance at the desktop. They can probably also replace a panel or a half.

    We'll be using Conky for this. It's intended as a geek toy with more system info and tiny graphs than even administrators will ever need. It does however also allow you to run your own scripts and print the output to the desktop. Note that since some of the scripts, I supply, assume you to be using a specific program (for mail, music etc.), they may be more relevant to you as inspiration for your own scripts. Feel free to write back if you need help setting it up.

    Install conky:
    Code:
    sudo apt-get install conky
    Conky is configured by way of a single file in your home directory, .conkyrc. To get a customized one, try the one attached to the thread and rename it.

    The .conkyrc file is divided into two: First comes global options, then a line saying 'TEXT' and then follows what you want it to display. Most global options are self-explanatory. Notice that we've got lines saying
    Code:
    own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
    ... and further down:
    alignment top_right
    gap_x 10
    gap_y 10
    which gives the conky window the same qualities as our terminal, so we'll not need to use wmctrl here (gap is the distance of the window to the corner set in alignment). Make sure to match the colour and font to the ones you use in your terminal for best effect.

    Code:
    TEXT
    ${alignr}${time %A %d %B} ${time %k:%M}
    ${alignr}${texeci 60 con_acpi}
    ${alignr}${texeci 10 con_mpc}
    ${alignr}${texeci 60 con_mail0}
    ${alignr}${texeci 60 con_mail1}
    ${alignr}${texeci 60 con_mail2}
    ${alignr}${texeci 60 con_torrent}
    ${alignr}${texeci 60 con_notes}
    As for text, conky reads one line at a time, so each line here is right aligned (by preceding the desired output with ${alignr} ). ${time %A %d %B} is a conky function that outputs the current weekday and date and ${time %k:%M} outputs the current time in hours and minutes. The ${texeci [interval] [script name]} lines each causes conky to run a script at the set interval and print the output. Please note that according to the conky web site this should be somewhat more taxing on the system than using conky functions - I haven't noticed any performance drain whatsoever (I'm on a 1.7 GHz 1Gb RAM system - adjust expectations according to your specs).

    You can add quite a lot of functionality to conky by using the inbuilt functions (see: http://conky.sourceforge.net/ and the thread http://ubuntuforums.org/showthread.php?t=205865 for more info). My point is to get something else out of it. Here's a few scripts that I've got it running. Copy/modify them if they're useful to you (and be sure to a) make them executable, b) add them to a directory covered by your path variable or use the absolute location).

    Unread mail (Thunderbird/mbox)
    Code:
    #! /bin/sh
    
    unreadmailcount=$(grep -c "X-Mozilla-Status: 0000" [path to your inbox])
    if [ $unreadmailcount -ge 1 ]; then 
        echo "You have $unreadmailcount unread mail in [ insert name of email account ]"
    fi
    This will scan your Thunderbird inbox file for the line "X-Mozilla-Status: 0000" which signifies an unread email and delivers the line count to be read out as "You have x unread mail in whateveryour@mailaddress.is" Conky supposedly has an mbox scanner but I havent't been able to get it to work.

    Notes
    This is a simple note taker that makes use fo the fact that we now always have a terminal at hand. Simply type 'cnote [content of note]', hit enter, and it'll appear shortly on your desktop courtesy of conky. To get rid of a note again, just type 'cnote rm [a single word or phrase appearing in the note, e.g. 'milk' to delete 'remember the milk!']. It doesn't get any easier.

    The 'cnote' script (the one we use to take down the note):
    Code:
    #! /bin/bash
    
    if [ "$1" = "rm" ]; then
    	notekeyword="$2"
    	for i in $(ls /home/user1/.notes/); do 
    		notecontent=$(cat "/home/user1/.notes/${i}")
    		if [[ "$notecontent" =~ "$notekeyword" ]]; then
    			echo "Deleting \"$notecontent\"..."
    			rm "/home/user1/.notes/${i}"
    		fi
    	done
    else
    	echo "$*" > /home/user1/.notes/note${RANDOM} && echo "Note saved"
    fi
    Replace '/home/user1/.notes/' with wherever you wish to save your notes (and be sure to create the directory) and save the script (the example above uses the name 'cnote' but use whatever name you see fit). We need to make a short script for conky that will let it read out all the note files we have saved in the note directory:
    Code:
    #! /bin/bash
    
    for i in $(ls /home/user1/.notes); do
    	cat "/home/user1/.notes/${i}"
    done
    Again: substitute and save.

    Torrents
    This is really simple. Most torrent clients have the option to move a finished torrent to a specific directory. This script simply scans that directory and reports any finds.

    Code:
    #! /bin/sh
    
    listcount=$(ls [path to completed torrents] | grep -c .)
    if [ $listcount -eq 1 ]; then
        echo -n "\"$(ls [path to completed torrents])\" has finished downloading";
    fi
    if [ $listcount -gt 1 ]; then
        echo "The following torrents have finished downloading:"
        ls [path to completed torrents]
    fi
    Music playing
    This is specific to the Music Playing Daemon, or MPD, and the client MPC. It simple formats the status output of MPC to produce a simple line displaying what song is currently playing.

    Code:
    #! /bin/sh
    mpcplaying=$(mpc status | grep -m 1 .)
    title=$(echo $mpcplaying | sed -e 's/^[^[^\-]*\ \-\ //g')
    artist=$(echo $mpcplaying | sed -e 's/\ \-\ .*$//g')
    if [ "$artist" != "$title" ]; then
        echo "MPD is playing \"${title}\" by ${artist}"
    fi
    Battery
    This shows battery power in percentage when running on battery power.
    Code:
    #! /bin/sh
    
    percentage=$(acpi | grep discharging | grep -o -E [0-9]+%)
    if [ -n "$percentage" ]; then
        echo "The battery has $percentage left"
    fi
    As some hardcore conkyheads may have noticed some of these duplicate built-in functions. The difference is that since we don't want tons of lines of text, these only display if there actually is something to report, otherwise you just get a blank line.

    Hope this has proved useful or provided some inspiration
    Attached Files Attached Files
    Last edited by chochem; March 10th, 2008 at 08:03 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •