Wednesday, April 17, 2013

Through tasker to send google talk message command for remote control via SL4A script


Through tasker to send google talk message command for remote control via SL4A script

 

I previously posted an entry about how to remote control android devices even on PC. And now this entry would be around how to send google talk message on your android device by a tasker shortcut created on launcher desktop.

 

Of course, to do that, you firstly need to  install “Python for Android" and the tool “SL4A” in your android device.

 

 

Step 1, please create 3 variables, %IM_USER, %IM_PSWD and %IM_TO in Tasker Variable tab. Each variable denotes the specific meaning referred to the form below.

 

Parameter
Required?
Description
%IM_USER
Yes
Your gTalk user ID, including the @gmail.com part
%IM_PSWD
Yes
Your gTalk password
%IM_TO
Yes
The address to which to send the IM
%IM_TEXT
Yes
The IM text

 

 

Step 2, create a new notepad file in the folder of sdcard/sl4a/script, copy the script context below and paste it all, then rename the file into sendIMupdated.py with .py as postfix. Or you may open SL4A tool and then click Add a new script, then paste the content in it. You may refer to the original post on link as follows to get to know more about SL4A. http://tasker.wikidot.com/sendim

 

 

import sys,xmpp

import android

droid = android.Android()

 

_SERVER = 'talk.google.com', 5223

 

try:

  IM_user = droid.getIntent().result[u'extras'][u'%IM_USER']

except:

  droid.makeToast('IM_USER missing')

  sys.exit(1)

 

try:

  IM_pswd = droid.getIntent().result[u'extras'][u'%IM_PSWD']

except:

  droid.makeToast('IM_PSWD missing')

  sys.exit(1)

 

try:

  IM_to = droid.getIntent().result[u'extras'][u'%IM_TO']

except:

  droid.makeToast('IM_TO missing')

  sys.exit(1)

 

try:

  IM_text = droid.getIntent().result[u'extras'][u'%IM_TEXT']

except:

  droid.makeToast('IM_TEXT missing')

  sys.exit(1)

   

jid=xmpp.protocol.JID(IM_user)

cl=xmpp.Client(jid.getDomain(),debug=[])

 

con=cl.connect(server=_SERVER)

if not con:

  droid.makeToast('ERROR: could not connect')

  sys.exit()

 

auth=cl.auth(jid.getNode(), IM_pswd, resource=jid.getResource())

if not auth:

  droid.makeToast('ERROR: could not authenticate')

  sys.exit()

 

cl.sendInitPresence(requestRoster=0)

 

cl.send(xmpp.protocol.Message(IM_to,IM_text, typ='chat'))



 

 

Step 3, in Tasker, Tasks tab, create 1 or 2 more tasks depending on your needs of message command.

 

e.g.:

 

Task: (Shut Off)

 

Action1: Variable-Variable Set-Name: %IM_TEXT, To: shutoff (or any other specific message command you like, set the corresponding trigger action on the receiver end android device, please refer to my previous entry about remote control part)

 

Action2: Script-Run SL4A Script-[Name: sendIMupdated.py Terminal: Off (means don’t check this option) Pass Variables: %IM_USER, %IM_PSWD, %IM_TO, %IM_TEXT ]

 

 

Step 4, after done, go back to your launcher desktop, create a shortcut, point to tasker cut, then select the task “Shut Off” you just created, select an icon for this shortcut btw.

 

Finally, you may simply press the shortcut to send specific message command to remote control your android device easily.

1 comment:

  1. Can anyone tell me how to automatically send a Voxer message with Tasker?

    ReplyDelete