How to create a single button to sequentially remove and add a tag to a certain tidlder

I want to create a single button which can do two things in a sequential manner

  1. On pressing the button first time, it should add a tag called tagA to tidlder 2 and remove the same tag tagA from tiddler 1
  2. On pressing the button the second time, it should add a tag called tagA to tidlder 1 and remove the same tag tagA from tiddler 2

I know to do this using two seperate buttons, but how to do it using a single button

If we can assume that, intially, either tiddler1 or tiddler2 (but not both) is already tagged with tagA, then the following button will switch the tags between the two tiddlers:

<$button> toggle tags
   <$action-listops $tiddler="tiddler1" $tags="+[toggle[tagA]]"/>
   <$action-listops $tiddler="tiddler2" $tags="+[toggle[tagA]]"/>
</$button>
  • If tiddler1 or tiddler2 does not yet exist, then clicking the button will create the tiddler and tag it with tagA.
  • If both tiddlers exist, but neither tiddler has tagA, then clicking the button will add tagA to both tiddlers.
  • Similarly, if both tiddlers already have tagA, then clicking the button will remove tagA from both tiddlers.
2 Likes

Thanks @EricShulman
That works perfectly.