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

TEXT
Stop in ${exec ~/.logout/time_left.sh}



The script time_left.sh which send remaining time to the conky :

#! /bin/bash

#st in seconds
st=$(~/.logout/read_time.sh)

RUNTIME=$((st))
SECOND=$((RUNTIME%60))
MINUTE=$((RUNTIME/60%60))
HOUR=$((RUNTIME/3600))

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

echo $HOUR":"$MINUTE":"$SECOND
if [ "$RUNTIME" -lt 0 ]; then
gnome-session-save --force-logout
fi




The script read_time.sh 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

log=~/.logout/.counter.txt
duration=3600

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

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

reste=-1
line=`tail $log`

xday=$(echo $line | cut -d";" -f1)
if [ $xday -eq $today ]; then
reste=$(echo $line | cut -d";" -f2)
hasdate=true
if [ $reste -lt 0 ]; then
reste=30
fi
reste=$((reste-1))
else
reste=$duree
fi
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 :

draw_smiley(200,175,120,4,0xFFFF00,false,true,false,
  "downspeedf", "wlan0",1000, false,
  "upspeedf", "wlan0",100, false,
  "wireless_link_qual_perc","wlan0",100,false,
  "acpitemp","",80,
  -0.5)

And the function with named arguments
function draw_smiley(xc,yc,radius1,shadow_size,color0,compo_r,compo_g,compo_b,
  le_name,le_arg,le_max,le_inv,
  re_name,re_arg,re_max,re_inv,
  mouth_name,mouth_arg,mouth_max,mouth_inv,
  color_name,color_arg,color_max,
  rotation)


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:
0xFFFF00,false,true,false,
with
"acpitemp","",80,
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.

Voilà!

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 shortcuts.py 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
rc_path_file="/home/ll/.config/openbox/rc.xml"
#template of conkyrc to use
conkytemplate_path_file ="/home/wlourf/scripts/raccourcis/conky_template"

#column width (Ms = souris, Kb= clavier)
lgColMs=50
lgColKb=40

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

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

#END OF THE PARAMETERS !



Third, a little bash script launcher.sh 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 launcher.sh with parameters :


<command>/home/wlourf/scripts/raccourcis/launcher.sh /tmp/conky_kb k</command>

<command>/home/wlourf/scripts/raccourcis/launcher.sh /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" ...