Remove Nat Sessions on a specific event

Ciao Rextended,
Unfortunatly (probably for my mistakes or fault) this is not working for me. By the way I've found a workaround to make it successfull.
With your high knowledge on Mikrotik scripts, I wanna ask you if is possible to create a script (that I'll implement with /system scheduler) that check if the default gateway have changed, and if yes launch a command /ip firewall connection remove blablabla that I already know is working cause I've tested it, but at this very moment I run it manually.
If I am not been clear let me know
Thank you in advance

Sorry for the bump, does anyone know or have any suggestion how to implement that?

How to obtain actual Gateway ID, compare it on previous stored ID value on memory, and if is different, remove all old NAT sessions

For debug
:global previousgw
:if ([:typeof $previousgw] != “id”) do={ :set $previousgw *0 }
:global defaultgw ([/ip route get [find where dst-address=0.0.0.0/0 and active=yes and !routing-mark]]->“.id”)
:if ($previousgw != $defaultgw) do={
:log warning “Previous GW ID $previousgw different to current GW ID $defaultgw”
:set $previousgw $defaultgw
} else={
:log info “The Gateway ID $defaultgw still the same”
}

Working example without debug frills
:global previousgw
:if ([:typeof $previousgw] != “id”) do={ :set $previousgw *0 }
:global defaultgw ([/ip route get [find where dst-address=0.0.0.0/0 and active=yes and !routing-mark]]->“.id”)
:if ($previousgw != $defaultgw) do={
/ip fire conn
:foreach idc in=[find where (timeout > 60)] do={
remove [find where .id=$idc]
}
:set $previousgw $defaultgw
}