Here is what I use to choose machine type at startup depending on what tool is connected.
I include a resistor connected to the sensor pin inside the tool connector. This gives a fixed temperature reading and lets the machine choose its type depending on what is connected at startup.
M308 S23 P"e2temp" Y"thermistor" T100000 B3950 A"ModeSelector" ;setup a thermistor input as config selection sensor
;wait for the sensor to start returning meaningful values (don't know if there is a better approach for this)
while sensors.analog[23].lastReading==0||sensors.analog[23].lastReading==2000
echo
;print the value detected (useful when adding a new mode)
;M117 ModeSelector value:{sensors.analog[23].lastReading}
;depending on sensor reading choose a system folder
if sensors.analog[23].lastReading==-273.1
M117 No Attachment Detected.
elif sensors.analog[23].lastReading<155
M117 Going to be a CNC.
M505 P"CNC"
else
M117 Going to be a 3D printer.
M505 P"Printer"
;load config.g from the chosen system folder
M98 P"config.g"