Draft: Fix #10596 broken "Refresh Scripts"
Requires review by Jehan who is most familiar with the code for menu building.
Lightly tested.
Note "Refresh Scripts" reorders menus, putting scripts at the bottom. Restart would reorder the menus again. I am not sure if that is a problem. If so, I think it is a separate issue.