On M1 Mac’s F4 was mapped to Finder. I wonder why since you can easily start Finder with Cmd ⌘
+ Space. To remap F4 you can run the following one line command from Terminal:
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0xC00000221,"HIDKeyboardModifierMappingDst":0x0C000002A2}]}'
Credit goes to the people who shared this on the Apple community, on the same link you can also find how to create an Automator application. You can also add this to your shell’s rc (run control), lately the default is zsh(rc) on macOS.