Android and Linux

Wednesday, August 11, 2010

Tasker

I've seen the app called Locale in the Market for a while and it seemed interesting. It allows you to do a lot of things automatically with the phone under certain conditions such as turning wifi on when you get home or putting your phone on silent at certain times. It looked nice but I didn't think I had much use for it until I noticed a Locale plugin called "Locale Execute" which allows you to execute scripts under whatever conditions you set. My first thought was "Cron!"

I started to download Locale but a lot of comments said it wasn't as good as Tasker. Since Locale is $10 and has no trial version, I installed the trial from the Tasker site. I played around with it for a day and decided to buy the full version.

Tasker looks pretty powerful. It can perform 160 built-in actions on virtually any conditions. Some of the conditions include time, location, day, application, various phone states (battery levels, plugging in headphones or USB, network connections, orientation, etc), various events (file opened or modified, display on or off, boot, shutdown, sdcard (un)mounted/removed, phone calls and SMS, gestures etc).

Talk about an app to show off to iPhone users.

So far, I've added a profile from their wiki which pops up a menu of shortcuts to all my audio apps whenever I plug in my headphones. I can then select which media app I want to use, Youtube, BeyondPod, Music, RockPlayer, etc.

Then I set up a location profile to turn on wifi when I'm within 200 meters of my house. This uses the cell tower for a location fix so GPS is not needed. I was previously using Timeriffic to turn it on at times which I'm normally home, but now it does it when I'm actually there.

Then I found a cooler use. You may remember my ip checking script that runs from cron on my home PC. It checks every 15 minutes and sends me a text message if the home IP address changes. I then copy the IP and put it in /sdcard/.hip to call from any scripts that connect to my PC. The command that calls it is a script named "hip", which stands for "Home IP" and simply does "cat /sdcard/.hip".

I've been using the same trick for well over a year and a half, since I had the iPhone, and always wanted a way to automatically put the IP in the /sdcard/.hip file. Such a simple task, but there's really no way to get the text from the SMS into a script, but it's quite simple with Tasker.

All I had to do was set it up to take action when a new SMS was received, which can be done according to the sender or the body of the SMS. The action I told it to take was to write to the file /sdcard/.hip.

One problem was that I send the SMS from sendmail using my Gmail address and I use a similar SMS trick for three different purposes, so I couldn't use the sender and had to use the body. I didn't see a way to have it look for an IP address, so I put a string in the SMS and had it look for that. I had to figure out how to do a wildcard, as that isn't documented on the Tasker site, but my script at home now sends this:

HomeIP:
xx.xxx.xxx.xx

I set tasker to look for "*HomeIP*". Apparently both asterisks are required for a wildcard as it didn't work with only one. Tasker writes the entire SMS to the file, including the sender, so /sdcard/.hip ends up looking like this:

FRM: me@gmail.com
MSG: HomeIP
xx.xxx.xxx.xx

I simply changed my "hip" script to: "tail -n1 /sdcard/.hip"

That's a pretty simple setup to solve a simple problem, but being able to automatically write files, or do any of the other things Tasker is capable of, on virtually any conditions, looks to be quite promising and powerful.

Followers