You don’t need to remap a key to menu item specifically; remap it to a null value or another key. To do this, use the hidutil
command to remap F9 to a null value, backspace, or something else.
hidutil property --set '{"UserKeyMapping":\
[{"HIDKeyboardModifierMappingSrc":0x700000045,\
"HIDKeyboardModifierMappingDst":0x700000000}]}'
Please note: the backslashes at the end of the lines allow this command to span multiple lines for readability. You can copy/paste this command as is or remove the backslashes for a true one liner
Now, the source (hex) value of F12 is 0x700000067 and the destination value is 0x700000000. I haven't tested this particular value but, should it not work, you can use 0x70000002A or 0x7000000E6 for a second backspace (it’s the key you intended to hit anyway), or something like right ⌥ Option respectively.
This solution is based on this answer which I previously wrote for a similar question; there are several codes for function keys listed there. If you need a list of hex codes for additional keys, Apple provides a Technical Note on hidutil
for your reference.