Android and Linux

Monday, November 1, 2010

Simple "to do list" voice script for Tasker/voice

I had to do something at work today which required me to examine several things to see if they needed done, do something to them, and mark them off my mental list of things that needed done.

This is something that nearly everyone does on a daily basis but there were just too many items on my todo list to remember them all so I took 10 minutes and whipped up this little script which I named "list".

#! /system/bin/sh
grep -E -i -q "add|delete" /sdcard/.voice || exec echo sorry
grep -E -i -q "^add|^delete" /sdcard/.voice && sed -i 's/^/list /' /sdcard/.voice

COMMAND=$(awk '{ print $2}' /sdcard/.voice)
ARG=$(cut -f3- -d ' ' < /sdcard/.voice)

if [ $COMMAND == "add" ]; then
echo $ARG >> /sdcard/list
echo "Added: $ARG"

elif [ $COMMAND == "delete" ]; then
sed -i "/$ARG/d" /sdcard/list
echo "Deleted: $ARG"

fi
This simply adds or deletes things from a list based on whether it finds "add blah blah blah" or "delete blah blah blah" in the file at /sdcard/.voice.

I created a new task in Tasker with the following actions:

1- Variable set %LIST to EOF
2- Locale Execute Plugin: @ list
3- Wait 500ms
4- Read Paragraph /sdcard/list to var %LIST
5- Flash %LIST

I set this to trigger on the keyword "list**" with the Tasker voice command I've been talking about in the last few posts. The end result is this:

I say "list add go to work"

It flashes:
go to work

I say "list add pay bills"

It flashes:
go to work
pay bills

I say "list delete work"

It flashes:
pay bills

I say "list add go on vacation"
It flashes:
pay bills
go on vacation

I say "list delete bills"
It flashes:
go on vacation

I say "list add sleep late"
It flashes:
go on vacation
sleep late

I added a line in the script to make this loopable. The line I added will add "list" to the beginning if it's not there already and execute normally. If called by the normal voice task, you still have to say "list add/delete blah blah blah" because "list" is the trigger word, but when called in a loop, you can just say "add/delete blah blah blah" and the script will recognize it. This makes it possible to keep using the list while performing your duties.

Followers