Some of my scripts for daily use on a linux desktop

Wednesday, March 31, 2010

Automatic logout for kids

I have a little problem with my little kid : when he plays on computer, I have to tell him at least 10 times to stop when his time is up !
So I wrote this conky (to use in Gnome) that will display remaining time and logout the session !
And after that, if he tries to login again, the session will run only 30 seconds ;-)

Of course, it's for a small kid who doesn't know commands like "killall conky" or tricks like that !

First, create a hidden folder in the kid session :
mkdir ~/.logout/

and create the next 3 files in the folder:
the conkyrc-logout

double_buffer yes
no_buffers yes

#own_window yes
own_window_type desktop
own_window_transparent yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below

border_inner_margin 0
border_outer_margin 0

# X font when Xft is disabled, you can pick one with program xfontsel
font 7x13

# Use Xft?
use_xft yes

# Xft font when Xft is enabled
xftfont monospace-18

# Text alpha when using Xft
xftalpha 0.5

# Draw shades?
draw_shades yes

# Stippled borders?
stippled_borders 0

# Default colors and also border colors
default_color yellow
default_shade_color blue

alignment br
gap_x 1
gap_y 1

# Add spaces to keep things from moving about? This only affects certain objects.
use_spacer right

# Subtract file system buffers from used memory?
no_buffers yes

Stop in ${exec ~/.logout/}

The script which send remaining time to the conky :

#! /bin/bash

#st in seconds


if [ "$SECOND" -lt 10 ]; then
if [ "$MINUTE" -lt 10 ]; then
if [ "$HOUR" -lt 10 ]; then

if [ "$RUNTIME" -lt 0 ]; then
gnome-session-save --force-logout

The script which read remaining time and save it in a file .counter.txt
The default time for a day is one hour (3600 secondes) on line 4.

#! /bin/bash


if [ ! -f $log ]; then
echo "no file"
echo $(date +%Y%m%d)";"$duration > $log

today=$(date +%Y%m%d)

line=`tail $log`

xday=$(echo $line | cut -d";" -f1)
if [ $xday -eq $today ]; then
reste=$(echo $line | cut -d";" -f2)
if [ $reste -lt 0 ]; then
echo $today";"$reste > $log

echo $reste

To run it at startup, add this line in gnome startup:
conky -c ~/.logout/conkyrc-logout

Voilà ! I'm sure there is other to do that, but I like the display of the remaining time...
Make sure the paths are OK for in the three files and don't forget to make the scripts executables

The script in french here.

Friday, March 19, 2010

Smiley Widget

Here is a new widget which can give at least four informations if you can read it, which is not really easy at first glance.
Each eye and the smile can be linked to a conky variable or not and color can change.
The code for the script can be downloaded on ubuntu forum or on CH forum (or in french here).

Parameters are explained in the Lua script, but there is a short example :

  "downspeedf", "wlan0",1000, false,
  "upspeedf", "wlan0",100, false,

And the function with named arguments
function draw_smiley(xc,yc,radius1,shadow_size,color0,compo_r,compo_g,compo_b,

From last to first :
-last line :rotation is the angle in radian of rotation of the smiley
-lines 2 to 5 are where we choose values to display. On line 2, it will display the download speed of wlan0, the value need to be in percent so we have to set the max value (1000 in my case). The last parameters will inverse the value if needed, ie. if value is 80%, it will draw a 20% value.
- first line : xc, yc, radius1 are for positionning the smiley in the conky window
- first line : shadow_size will draw a shadow ;-)
- first line : color0, compo_r, compo_g, compo_b are parameters for having color changing, for the example above:
The color will change between 0 and 80, at zero, color will be 0xFFFF00 (yellow) and when $acpitemp will increase, green composante will be affected, so when 80°C is reached, the color will be 0xFF0000 (red).

Last warnings :
Fixed values can be used instead of conky variables with name="" and arg=value (80% in this case): "",80,100,false,

If you call more than one widget : xc, yc and rotation are RELATIVES to previous widget.


Wednesday, March 10, 2010

How to display Openbox's Shortcuts

I am an Openbox + Ubuntu user but sometimes, I can't remember some shortcuts. So I wrote a script to display the shorcuts (keyboard+mouse) from rc.xml in a conky window, and this window is called with a shortcut (!) only when I need it, it's a kind of help window :-)

Maybe this kind of script already exist but I didn't find it .

All the scripts can be downloaded from ubuntu forums.
In french, it's here on ubuntu-fr forum.

First I need a conkyrc template.
The python script will read this file and write shortcuts at the end of this file but in a new file.
The only thing to do in this file is to choose your colors for display.
The name of the file is conky_template.

Second, the python script read the openbox's rc.xml file.
There are some parameters to set at the beginning of the script :

#full path and name of the rc.xml file
#template of conkyrc to use
conkytemplate_path_file ="/home/wlourf/scripts/raccourcis/conky_template"

#column width (Ms = souris, Kb= clavier)

#Number of lines per Column (Ms = souris, Kb= clavier)

#in "Keyboard" array, "appliFirst" will display application name before shorcut


Third, a little bash script needed to run the python script and to call conky. Don't forget to make it executable.

And, for finish, in rc.xml, two shortcuts to run with parameters :

<command>/home/wlourf/scripts/raccourcis/ /tmp/conky_kb k</command>

<command>/home/wlourf/scripts/raccourcis/ /tmp/conky_ms m</command>

Voilà, when I call the script, the conky display the above image for the keyboard or this one for the mouse :

Today I also updated the audio_spectrum script : it can display the bargraph widget in a circular way, like this :

And a short video :

Monday, March 1, 2010

Bleeding heart ...

I made this amazing heart with a Lua script. The verticals lines are linked to some conky variables (cpu, download speed ...).
It's up to the user to choose the shape he wants to draw, for example a breathing heart :

Well, I am not specially interesting by hearts but I tried to adhere to the theme of the conky contest of this month : Saint Valentine's Day/Massacre. So, if you like this script, you can vote for it on the conky blog here.

A last video made with the same script :

All the stuff can be downloaded from the ubuntu forum : here. There is also an HOWTO if you want to draw your own shapes!

I think, I will stop with this moving stuff for a while !

Happy Conkying ! And if someone can explain me the difference between "bleeding" and "bloody" ...