Tuesday, September 23, 2014

Tasker AutoRemote - Remote Programming Of Your Android Device, The Easy Way

Tasker AutoRemote is a slick little Android App that allows you to remotely access your Android device from any Net connected device. It effectively provides you with a URL you can invoke and thereby pass messages to your phone. Those messages can then be acted upon by Tasker.

Once I worked out a few kinks, Tasker AutoRemote became a fun way to integrate remote Linux servers with my phone. Consider the notification from the command line "problem" I worked out a while back. To summarize, I wanted a way to have my computer notify me when a long running task was done. The solution was speak.exe, an AutoHotKey app that uses text-to-voice to get my attention. I can now run the following command locally::

  make ; speak "Done compiling. Back to work"

With AutoRemote, it's trivial to extend this example so that I can run:

  make ; andsay "Done compiling. Back to work!"

and have the voice chime in over my phone. I don't need to be in front of my computer any longer, and the command works just as well on my local desktop, as it does on a far off remote Linux server.

On the Linux side, I've implemented a general purpose andsend script that invokes my device's URL with arbitrary arguments and content being read from stdin:


## Send data to an android device using Tasker's Auto Remote

if [ $# -eq 0 ] ; then
  echo "Usage: `basename $0` command [arg ...]"
  exit 1
  command=$1 ; shift
  while [ $# -gt 0 ] ; do
    command="$command $1" ; shift

echo -n "$command=:=" > $tmp
cat                  >> $tmp

curl -s $base -d "key=$key" --data-urlencode "message@$tmp" > /dev/null
rm -f $tmp

I've then setup a number of wrapper commands that invoke andsend. Here's andsay's:

andsend "Say"

And here are the scripts for andclip, which stores text in my Android device's clipboard and andsms which fires off an SMS to a number of my choice:

-- andclip
andsend "SetClipboard"

-- andsms
if [ -z "$1" ] ; then
  echo "Usage: `basename $0` phone-number"
  andsend SendSms $1

It's all pretty basic stuff. I'm leveraging the convention that AutoRemote uses that messages have the format: word1 word2 ...=:=arbitrary text....

Most of the magic happens on the Android side of things. And even then, the profile to implement andsay is pretty trivial. Here's the Tasker description for it:

Profile: AutoRemote, Say (35)
State: AutoRemote [ Configuration:^Say (regex) ]
Enter: Anon (36)
  A1: Say [ Text:%arcomm
            Continue Task Immediately:Off ] 

With this in place, I can type the command in my office, to be run on a server in Denver, and be notified of the task completion while I'm making lunch in the kitchen. Life is good!

1 comment:

  1. Anonymous11:41 PM

    Thanks mate, it is simple but is exactly doing what I need



Related Posts with Thumbnails