You don't need to, and shouldn't, create the script directly in the context menu. Save it as a Rename Preset instead, which you can then use from any place you need it (including in the Rename dialog itself).
-
The script should be saved as a Rename Preset, within the Rename dialog.
See How to use Rename Presets from this forum, and the Rename Scripts (not inside a Preset) part specifically, for how to do that.
-
Once the preset is made, in the context menu, you can use the command I mentioned above:
Rename PRESET="My Preset"
(Where
My Preset
is your preset name.)