Good morning, Dave...
Making your PC say hello.
Independence Day was on TV the other day and Jayne asked why I hadn't set up my computer to say good morning to me like Dave's laptop in the film, obviously an idea stolen from 2001. I'd completely forgotten about it until this morning when I figured I'd have a go at hacking something together, the result is the bash script below.
The script should get your name from the /etc/passwd file and use espeak to say "Good morning/afternoon/evening" depending on the time of day. Just add it to the startup programs of whatever desktop environment you use (or add it to .bashrc if you use the console only).
If anyone knows of an alternative to the ugly way I've managed to get the users first name from /etc/passwd I'd love to know.
Update: Thanks to the un-named person below who suggested using finger to get the user's name, much better!
#!/usr/bin/env bash
## Says good morning/afternoon/evening etc.
## Requires the espeak package.
## Set name using finger
name=$(finger -l $USER | sed 's/.*: //;q')
set -- $name
name=$1
## If this doesn't work you could just set the
## name manually.
# name="Luke";
## What time is it? Use the hour to work out
## whether it's morning, afternoon, or evening.
declare -i time;
time=`date +%H`;
if [[ $time -ge 12 && $time -le 17 ]] ; then
timeofday="afternoon";
elif [[ $time -ge 18 && $time -le 23 ]] ; then
timeofday="evening";
else
timeofday="morning";
fi
## Say hello
say="\"Good "${timeofday}" "${name}"...\"";
espeak -s 120 "${say}";
exit 0;


windows cheat
this is more clever, though. i think i'll distract myself from revision by trying to understand it.