Termux - passing variable to Tasker

577 views
Skip to first unread message

Igor Czarnecki

unread,
Oct 20, 2021, 1:38:04 PM10/20/21
to Tasker
Hello!
Ive got problem and im stucked.
im using shell scripts in termux to call actions in tasker.
im doing it like here:
so for example i can send sms like so:
#tasker#
system-> intent received action: net.dinglish.tasker.send
task:
send SMS: Number: %number; Message: %message
#termux# send.sh
#!/data/data/com.termux/files/usr/bin/sh
am broadcast --user 0 -a net.dinglish.tasker.send -e number "$1" -e message "$2" > /dev/null
so when i execute send.sh 1234567 foo it send "foo" to 1234567
as you can see i can pass variable $1 and $2 and everything is working well.

But from few days im trying to send whatsapp message like this:
#Tasker#
profile: whatsapp
Action: phone->contact Via App 
contact: MichaelX
app: .../vnd.com.whatsapp.profile
text: TEST_TEXT
#termux#
#!/data/data/com.termux/files/usr/bin/sh
(this way) am broadcast --user 0 -a net.dinglish.tasker.whatsapp > /dev/null
(or this way) am broadcast --user 0 -a net.dinglish.tasker.whatsapp -e number "$1" -e message "$2" > /dev/null
But when im executing it, whatsapp isnt opening and im geting the Text value inside termux and output "TEST_TEXT" (or %variable) command not found...
How can I do it? How can I call it? Or maybe do YOu know any other way to call it from termux...

Thank You so much, couse im out of ideas how can i pass it.

jmjc...@gmail.com

unread,
Oct 20, 2021, 9:50:14 PM10/20/21
to Tasker
So, have you created the Intent Received profile for WhatsApp (like you did for your SMS)?

Igor Czarnecki

unread,
Oct 21, 2021, 3:19:58 AM10/21/21
to tas...@googlegroups.com
Hello,

Thank You for answear. Im worried that there isnt a lot of people which can help me with that.

So, yes just like You said I've created profile exactly same as for sms inside tasker. (In termux: tasker5.sh is for sms, tasker4.sh is for whatsapp):

~/backup/180821 $ cat tasker5.sh
#!/data/data/com.termux/files/usr/bin/sh
am broadcast --user 0 -a net.dinglish.tasker.sms
~/backup/180821 $ ./tasker5.sh
Broadcasting: Intent { act=net.dinglish.tasker.sms }
Broadcast completed: result=0
(sms sent correctly here with TEST_TEXT)

~/backup/180821 $ cat tasker4.sh
#!/data/data/com.termux/files/usr/bin/sh
am broadcast --user 0 -a net.dinglish.tasker.wa
~/backup/180821 $ ./tasker4.sh
Broadcasting: Intent { act=net.dinglish.tasker.wa }
Broadcast completed: result=0
~/backup/180821 $ TEST_TEXT
TEST_TEXT: command not found
(whatsapp isnt opening, ive only get TEST_TEXT output (plain text) in termux).

When Im running whatsapp task inside tasker everything is fine, the message is send, to selected contact, with TEST_TEXT message.

--
You received this message because you are subscribed to a topic in the Google Groups "Tasker" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tasker/EH-9M732K-g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tasker+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tasker/9b034dae-88dd-4bd2-87c7-37c1145470a2n%40googlegroups.com.

jmjc...@gmail.com

unread,
Oct 21, 2021, 3:39:59 AM10/21/21
to Tasker
Could you share the description of your whatsapp profile? Long click on profile name -> 3-dot menu -> Export -> Description, anf then paste it here.

Igor Czarnecki

unread,
Oct 21, 2021, 4:05:09 AM10/21/21
to tas...@googlegroups.com
Sure:

    Profile: Whatsapp1
    Settings: Restore: no
    Event: Intent Received [ Action:net.dinglish.tasker.wa Cat:None Cat:None Scheme:* Mime Type:* ]
    
    
    
    Enter Task: wysyleczka
    
    A1: Contact Via App [
         Contact: AlaxZz
         App: vnd.android.cursor.item/vnd.com.whatsapp.profile
         Text: TEST_TEXT
         Back Out: On Continue Task After Error:On ]
    
    

jmjc...@gmail.com

unread,
Oct 21, 2021, 4:28:28 AM10/21/21
to Tasker
When you run tasker4.sh in Termux, is your phone's display on and unlocked?

Igor Czarnecki

unread,
Oct 21, 2021, 4:41:20 AM10/21/21
to tas...@googlegroups.com
Yes, it is. I just need it for sending few prepared messages on whatsapp instead of sms (one of my customer needs to receive it via whatsapp), so there is no need to lock screen.

jmjc...@gmail.com

unread,
Oct 21, 2021, 4:54:15 AM10/21/21
to Tasker
To make sure Tasker does receive the Intent, could you add a Flash "Whatsapp Intent received!" action in the entry task? Just want to make sure when you run tasker4.sh, you see the Flash message.

Igor Czarnecki

unread,
Oct 21, 2021, 7:02:49 AM10/21/21
to tas...@googlegroups.com
Sorry for delay. Everything looks ok...


Screenshot_2021-10-21-13-00-52-720_com.termux.jpg

jmjc...@gmail.com

unread,
Oct 21, 2021, 9:03:23 AM10/21/21
to Tasker
Just curious, why are you doing this from Termux?

Igor Czarnecki

unread,
Oct 21, 2021, 9:13:11 AM10/21/21
to tas...@googlegroups.com
Ive got a lot of scripts using termux api. More than 30, few k lines of code. But... if that doesnt work, is there other way to do so?
For example I can put those meesages into files in specific folder and tasker will send it? Is it possibile? Or any other way?
I have no idea why its working with sms, and isnt working with whatsapp...

jmjc...@gmail.com

unread,
Oct 21, 2021, 9:15:55 AM10/21/21
to Tasker
If you run the task manually and it works but doesn't work when you send an intent from Termux, I have no idea. The only different between sending sms and WhatsApp is sending WhatsApp requires the display be on and unlocked.

ktmom

unread,
Oct 21, 2021, 9:17:58 AM10/21/21
to Tasker
Based on your descriptions, it looks like you're using " e message" in the intent sent from Termux but trying to use "TEST_TEXT" in the Tasker task.  You should be using %message in the Tasker task just like you do in the SMS task.

Igor Czarnecki

unread,
Oct 21, 2021, 9:32:28 AM10/21/21
to tas...@googlegroups.com
Ok guys ive got it!
Ive set all permissions (probably to whatsapp can pop-up in front of all) and it work. Ohhhhh so many tries... :)
Thank You jmjcc, without You i will give up with this. That will improve my work even more. If You ever will have questions about linux/termux-api i will glad to help.




jmjc...@gmail.com

unread,
Oct 21, 2021, 9:39:28 AM10/21/21
to Tasker
Great! Yes, will ask you about Termux stuff when needed. Thanks!

jmjc...@gmail.com

unread,
Oct 21, 2021, 10:35:38 AM10/21/21
to Tasker
To answer your earlier question, yes, you can put contact+message information in a text file and Tasker can read the file and send the messages.
Reply all
Reply to author
Forward
0 new messages