SWS cycle actions is what you need.
You didn't specify, whether you need track or global automation mode change, so I assume that it is global.
Install SWS extensions.
Extensions->Cycle action editor.
Right-click on the left side and add. Call it somehow.
Choose the action and right-click on the right side->Add.
Just type in to command column these values and if everything is correct, you'll get descriptions of the actions. Click Apply on the bottom-left corner. Do the same with the second picture. You'll find these actions in Actions window, so call them wisely.
The idea is simple: it runs the first custom and if the second action is ON, the custom turns it OFF. The same is with the second custom, but it checks, whether second action is OFF and if so, turns it ON.