• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

GUIDE: (Difficulty: Intermediate) Run Shell Scripts in Tasker(1)

Search This thread

loubot

Member
Jan 13, 2016
12
8
Context: You want to get some useful information about your device and store it in Tasker to further usage. Here is a guide showing some useful commands you can use from Tasker. Remember you must check root to make them work.

Requirements :Root

I. Battery Status: Display your battery level, health and temperature.

Task
1. Run Shell> Command: "dumpsys battery | grep health" Store Output in: %Dump2. Gets and stores the specific information in a variable.
2.Variable split: %Dump2 Splitter : Avoids repeating the word health
3.Run Shell > Command : "dumpsys battery | grep temperature" Store Output in : %Dump3
4. Variable Split: %Dump3 Splitter :
5. Variable Section: Name: %Dump3 From 2 Lenght 2 Avoids the incorrect format in Celsius
Now you have the info about your battery. If you want your device to say it to you proceed as following. The If conditions is necessary because the health is given in numbers from 1 to 5.
6.If %Dump22 Matches Regex 1
7. Say The battery level is %BATT and the health is excellent. The temperature now is %Dump32 degrees.
8. End if
9. .If %Dump22 Matches Regex 2
10. Say The battery level is %BATT and the health is very good. The temperature now is %Dump32 degrees.
11. End if
12. If %Dump22 Matches Regex 3
13.Say The battery level is %BATT and the health is good. The temperature now is %Dump32 degrees.
14. End if
15. If %Dump22 Matches Regex 4
16. . If The battery level is %BATT and the health is weak. The temperature now is %Dump32 degrees.
17. End if
18. If %Dump22 Matches Regex 5
19. Say The battery level is %BATT and the health is critical. The temperature now is %Dump32 degrees.
20. End if
As you created global variables, you can do whatever you want with them in Tasker, for an example create a widget.
In a next thread I will show you how to get info about the time your device is on since boot and about your storage.
 

MishaalRahman

Editor in Chief
Nov 2, 2015
1,042
2,132
www.xda-developers.com
This is a good method for pulling battery information if you're rooted. If you're not rooted, you can read the files in /sys/class/power_supply/battery to get the same information. Use current_now for the current, voltage_now for the voltage, temp for temperature.
 

loubot

Member
Jan 13, 2016
12
8
This is a good method for pulling battery information if you're rooted. If you're not rooted, you can read the files in /sys/class/power_supply/battery to get the same information. Use current_now for the current, voltage_now for the voltage, temp for temperature.

Good point. As it is getting more and more difficult to root a device, it is important to have other options. The main purpose of the guide is nevertheless make people more familiar with some commands that you can also use on the Android Terminal Emulator.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 3
    Context: You want to get some useful information about your device and store it in Tasker to further usage. Here is a guide showing some useful commands you can use from Tasker. Remember you must check root to make them work.

    Requirements :Root

    I. Battery Status: Display your battery level, health and temperature.

    Task
    1. Run Shell> Command: "dumpsys battery | grep health" Store Output in: %Dump2. Gets and stores the specific information in a variable.
    2.Variable split: %Dump2 Splitter : Avoids repeating the word health
    3.Run Shell > Command : "dumpsys battery | grep temperature" Store Output in : %Dump3
    4. Variable Split: %Dump3 Splitter :
    5. Variable Section: Name: %Dump3 From 2 Lenght 2 Avoids the incorrect format in Celsius
    Now you have the info about your battery. If you want your device to say it to you proceed as following. The If conditions is necessary because the health is given in numbers from 1 to 5.
    6.If %Dump22 Matches Regex 1
    7. Say The battery level is %BATT and the health is excellent. The temperature now is %Dump32 degrees.
    8. End if
    9. .If %Dump22 Matches Regex 2
    10. Say The battery level is %BATT and the health is very good. The temperature now is %Dump32 degrees.
    11. End if
    12. If %Dump22 Matches Regex 3
    13.Say The battery level is %BATT and the health is good. The temperature now is %Dump32 degrees.
    14. End if
    15. If %Dump22 Matches Regex 4
    16. . If The battery level is %BATT and the health is weak. The temperature now is %Dump32 degrees.
    17. End if
    18. If %Dump22 Matches Regex 5
    19. Say The battery level is %BATT and the health is critical. The temperature now is %Dump32 degrees.
    20. End if
    As you created global variables, you can do whatever you want with them in Tasker, for an example create a widget.
    In a next thread I will show you how to get info about the time your device is on since boot and about your storage.