Kodi how to create an ON / OFF toggle switch for a single button

Typically for Kodi I tend to assign one button to one task. eg. power up and another for power down. Its just simpler and I normally run a shell script that runs a program or calls WGET with the required parameter for web controlled units like the WeMos D1 mini (ESP8266 board) connected to a 433mHz RC unit

So say you want to override the on/off toggle on a remote (not all units support this) you could bind it to a single shell script. This script would check for a file and if present run one command say command A and delete the toggle file. When the script was rerun the script would not find the toggle file, we deleted it as part of the first run ,so the script would run command B and recreate the toggle file.

I created 3 files one to turn on the AVKit, one to turn if off and toggleavpower.sh:

toggleavpower.sh:

TOGGLE=$HOME/.toggle

if [ ! -e $TOGGLE ]; then
    touch $TOGGLE
    echo "Flag created, turn on AV"
    /storage/avon.sh
else
    rm $TOGGLE
    echo "Flag file found and removed, turn off AV"
    /storage/avoff.sh
fi