Personal tools
You are here: Home Blog Good morning, Dave...

Good morning, Dave...

Posted by lukepomfrey at Jan 08, 2009 02:50 PM |
Filed under: , , ,

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;
Document Actions
  • Send this
  • Print this
  • Share this

windows cheat

Avatar Posted by Jack Carlyle at Apr 21, 2009 05:40 PM
you could just make the start up sound a recording, much easier.
this is more clever, though. i think i'll distract myself from revision by trying to understand it.

Windows cheat

Avatar Posted by lukepomfrey at May 23, 2009 01:01 PM
Yea, but then you'd need a different recording for every user. This is a bit more portable.

finger

Avatar Posted by asdfasdf at May 30, 2009 06:48 PM
finger -l $USER | sed 's/.*: //;q'

finger

Avatar Posted by lukepomfrey at Aug 26, 2009 04:08 PM
Hadn't thought of using finger. Much better, thanks.

Add comment

You can add a comment by filling out the form below. Plain text formatting.

Info
Note: you are not logged in. You may optionally enter your username and password below. If you don't enter your username and password below, this comment will be posted as the 'Anonymous User'.
(Required)
(Required)