There is no ogscript command to add/remove tasks specifically.
There are 2 ways I can see to do something like this:
1. I would just use a parameter to store whether the Button2 task should run or not. Button1 sets that parameter to 1, button 3 sets that parameter to 0. Button2 checks if the parameter is 1 before running anything.
2. There is a "setXML" method that allows us to change the oglml of a particular element. You would need to specify the entire button definition, but it should work. Here is an example:
<abs contexttype="opengear" id="_top" keepalive="false" style="">
<button buttontype="push" height="68" left="470" name="Button1" top="105" width="179">
<task tasktype="ogscript">var xml = '<button buttontype="push" top="0" id="button2_id" left="0" name="Button2" bottom="0" right="0">';
xml = xml + '<task tasktype="ogscript">';
xml = xml + ' ogscript.debug("I am button2, set by button1")';
xml = xml + '</task>';
xml = xml + '</button>';
ogscript.setXML('button2_abs', xml);</task>
</button>
<abs height="81" id="button2_abs" left="219" top="277" width="190"/>
<button buttontype="push" height="68" left="471" name="Button3" top="242" width="179">
<task tasktype="ogscript">var xml = '<button buttontype="push" top="0" id="button2_id" left="0" name="Button2" bottom="0" right="0">';
xml = xml + '<task tasktype="ogscript">';
xml = xml + ' ogscript.debug("I am button2, set by button3")';
xml = xml + '</task>';
xml = xml + '</button>';
ogscript.setXML('button2_abs', xml);</task>
</button>
</abs>
Click on Button1 to make Button2 appear, then click on Button3 to change what it does. You'll need to have the openGear Debug Information window open to see what the buttons do since they only do debug messages.
#DashBoard