@mdalacu For the Meta Gcode programming language, see https://docs.duet3d.com/en/User_manual/Reference/Gcode_meta_commands
For a list of the Object Model variables, see https://github.com/Duet3D/RepRapFirmware/wiki/Object-Model-Documentation
There are OM entries for:
state.currentTool - Number of the currently selected tool or -1 if none is selected
state.nextTool - Number of the next tool to be selected
state.previousTool - Number of the previous tool

And quite a few in the tools[] section that might be useful https://github.com/Duet3D/RepRapFirmware/wiki/Object-Model-Documentation#tools

Ian