Android and Linux

Friday, July 8, 2011

Roku searcher

I thought I was done with the Roku but I realized it's a pain to type out a search phrase by running a command for every letter, so here's a way to automate it.

This is geared toward Android phones. For Linux, just change /system/bin/sh to /bin/sh and you might need to change the file on the third line from /sdcard/typer to something else.

What this does is take a phrase from a file and changes the spaces to a "-". They have to change because there's no simple way to recognize the space character as a space. Then it puts a real space between every character so they can be picked out easily, then reads them one at a time and hits the appropriate Roku URL to input that character.

Using Tasker on Android, you can use the Variable Query action to pop up a text box, type "this is a test", write that to a file then execute this script. It will read the phrase, turn it to "T h i s - t e s t", read every character except the spaces, and hits the correct url for that character.

It has to wait between each character or the Roku may not catch every request. Unfortunately, on Android, the minimum wait time is 1 second. On Linux, you can set the sleep command to .3 seconds, trigger this script and watch the characters appear on your TV screen almost as if someone were carefully typing it.

#! /system/bin/sh
ip=YOUR ROKU IP

for i in $(cat /sdcard/typer | sed 's/ /-/g' | sed 's/./& /g')
do
if [ "$i" = "-" ]
then
wget -q -O - --post-data "" "http://${ip}:8060/keypress/lit_ "; sleep 1
else
wget -q -O - --post-data "" "http://${ip}:8060${click}/keypress/lit_${i}"; sleep 1
fi
echo
done

Followers