Toggle a widget between 2 icons with AutoTools Text Toggling

Learn how to toggle between 2 values and apply that to a widget on your homescreen

  1. joaomgcd
    This is how it'll look like:


    STEP 1 - CREATE TASK AND WIDGET


    • Create a task called Toggle
    • Add a Flash action with the text Toggling...
    • Go back to your home screen and add a Tasker widget (not shortcut because that one's icon can't be changed)
    • Select the Toggle task
    • Give it a green arrow pointing right icon
    • Accept
    • Check how touching it will show the word "Toggling..."


    STEP 2 - TOGGLE %ICON


    • Go back to the task and add a Set Widget Icon variable
    • Set Name to Toggle
    • Set the icon to the left arrow pointing left icon
    • Touch the little switch-arrows icon like in the video (you need to disable beginner mode in Tasker's settings for this to show up)
    • Copy the icon's full path
    • Go back to the task and add an AutoTools Text action
    • Set the Text field to %Icon
    • Set the Toggle field to android.resource://net.dinglisch.android.taskerm/drawable/cust_profile_exit_dark=:=
    • Use the same process to get the green arrow icon's full path and append it to the Toggle field so that it's set to android.resource://net.dinglisch.android.taskerm/drawable/cust_profile_exit_dark=:=android.resource://net.dinglisch.android.taskerm/drawable/cust_profile_enter_light
    (i) %Icon is the variable we want to toggle. By setting the Toggle field to the value above we're saying that if %Icon is the red arrow (value on the left of =:=), it should be set to the green arrow (value on the right of =:=) and vice-versa. It doesn't have a value yet so it will first assume the value on the left of =:=.
    • Add a Variable Set action where you set %Icon to the result of the toggle which is %attextresult(1)


    STEP 3 - TEST


    If you now go back to your home screen and tap the Toggle widget it should change its icon to a red arrow. If you tap it again it will turn green and so on.



    In a real world situation the variable stored globally will more likely be a simple status, such as on|off or left|right etc instead of the icon path directly.
    In that situation you can change the image accordingly, like this for example:

    Code (Text):

    A1. Flash: Toggling
    A2. AutoTools Text:%Toggle   on=:=off
    A3. Variable Set: %Toggle To: %attestresult(1)
    A4. Set Widget Icon (right/green arrow pic) If [ %Toggle ~ on ]
    A5. Set Widget Icon (left/red arrow pic) If [ %Toggle ~ off ]
     
    This will make it easier for you to both select the appropriate image and also do other stuff in the task that depends on the %Toggle status.

    Thanks for the tip Ratchet_Guy! ;)
    giovanclaros likes this.