# Owner: glow # KeyID: E65A8520F36AEE13CFE4F56BEB8FE331063A4794 # Key: https://glow.li/pgp # Verify: curl "https://glow.li/posts/pass-variables-from-termux-to-tasker/index.html.asc" | gpg -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 +++ { "date": "2016-04-03", "layout": "post", "oldurls": ["technology/2016/4/03/pass-variables-from-termux-to-tasker/"], "tags": ["Technology", "Termux", "CLI", "Tasker", "Android", "Tutorial"], "title": "Pass variables from Termux to Tasker" } +++ I figured out that you can pass variables from Termux to a Tasker task. This example sets Android's volume to a value specified in Termux. ## Step 1: Creating the script volume.sh ``` #!/data/data/com.termux/files/usr/bin/sh #am broadcast --user 0 -a net.dinglish.tasker.[task name] -e [variable name] "[value]" > /dev/null am broadcast --user 0 -a net.dinglish.tasker.volume -e volume "$1" > /dev/null ``` ## Step 2: Create a Tasker profile ![Screenshot](media/images/TaskerVolume1){.right .size-half} 1. Create a new profile 2. Choose "Event" 3. In the "Select Event Category" dialog choose "System"->"Intent Received" 4. As Action define `net.dinglish.tasker.volume` This profile will now be called whenever it receives the "volume" intent. ## Step 3: Create the Task ![Screenshot](media/images/TaskerVolume2){.right .size-half} 1. Tap "New Task" and give it a name 2. Tap + to add a new Action 3. Choose "Audio"->"Media Volume" 4. Under "Level" tap the icon with the crossing arrows to switch to text mode. 5. Enter `%volume` as a value 6. You need to exit Tasker for the changes to take effect. ## Step 4: Run the script You can now run the script. It will send an intent to Tasker. It will put the first argument as new volume, which has to be an integer from 0-15. ``` ./volume.sh 4 ``` This is only a simple example of what you can do with variables. Let me know what you come up with. -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE5lqFIPNq7hPP5PVr64/jMQY6R5QFAmevrjQACgkQ64/jMQY6 R5SyFw//T0X2V5OgnPBBgnE4pnTsvI3HQrusCO8Z4oBgca4NcVQlnRTwAfZROJjX HWlKpGNICQRvcgapHYJ0GeOZzJda101jmVla09WH9p638pEk9GQD2tEGtsftHijO GeAF0vRV2/tGGmpzmlVEyorV0Aw1WMGWt3a8weDbYDtOHen3g0CcRDHmrH9Y6gjp Ht+ClgdaSxVwR8nJDmZb4o3+dNQRrRly4OJSn5nnQvokJIl3tMiWgZ5+kxQtAAqu xBRnzle2UVyr+AlIVPdjbEWxA4keDTf0n/eR4wUU5h/rKWe9cjOUeO3Q1bW/VbW8 VbIvrOw1ct1G8KCruFbL3J8Eek5d4hcRi8yJD38di2O02/PyylRrVCb40RwjImAY dOTfp16e6u1Fh9LWJz/vIOOfPbCaHgj3Em0hW976BK/zdt3gZhIc5ThTTr/mqQJg BqE1nuM3sF3PqHEQacV+GmGNQbfnTo5Zr0jVByCCWCMQZ93jga3oNGxLC8KGy2py V4gcgYzZXoOBUt2QvITTAYYsQi3Wmgfbe0IPOB/DJsah6XcN6BfFzUdz+3Jknvb0 Q6PuPfsQG2qoSHUXA9ygq8uTONZNjnnp8m87kkeeo6+c3n1RIwLrRa/kr4LRFrlj aaXKZgOF0c4+oqB1g88eyUMjKb2Jh5870CPKa+CqbEtD2Ha3+Wo= =MXBp -----END PGP SIGNATURE-----