Android and Linux

Sunday, October 30, 2011

Run Tasker task from command line

I have been looking for an alternative to Notify My Android in order to send myself notifications to my phone when I'm at home. NMA notifications work fine, but you have to open the app to clear them and I just wanted a vibration or sound that didn't leave anything else on the phone for when a job finished at the computer or something.

I first looked at playing a media file with the following command:

am start -n -d /sdcard/foo.mp3

That sorta works. It opens the media app and plays the file then immediately goes to the next song. Adding && sleep 1 && pkill makes it work more like I wanted, but that's too ugly.

I ran across this post in the Tasker forum about invoking a task from the command line, but the consensus was that it wouldn't work unless the command line app has the right permissions.

But then I discovered that this works:

am broadcast -a -e task_name YOUR_TASK_NAME

The only difference being the "-e" option instead of "-es."

So I made a simple script called "task" for the phone.
#! /system/bin/sh
am broadcast -a -e task_name "$*"
Now I can bounce the command off the phone via ssh and run any Tasker task I want.