Ukelele can create a keyboard variation where tilde ~ is not a dead key, probably your best bet if you can get it to launch without hanging. You can always type ñ by holding down the n key for a second. Karabiner-Elements, AppleScript, etc. can only type what your keyboard supports, e.g., these bash commands with Karabiner:
cat > ~/.config/karabiner/assets/complex_modifications/azerty-tilde.json <<.
{"title": "AZERTY tilde",
"rules": [
{"description": "AZERTY tilde emits space after dead key ~ (option-n) for French keyboard.
Bug: auto-repeat gets only spaces after the initial tilde.",
"manipulators": [
{"type": "basic",
"from": {"key_code": "n", "modifiers": {"mandatory": ["option"]}},
"to": [{"key_code": "n", "modifiers": ["option"]},
{"key_code": "spacebar"}]}]}]}
.
Now the "AZERTY tilde" rule is installed.
Open -a Karabiner-Elements
Pick this Karabiner-Elements menu sequence to enable the "AZERTY tilde" rule:
Window > Karabiner-Elements Preferences > Complex Modifications > Rules > Add Rule
In the Add rule window, find "AZERTY tilde" on the left and use the corresponding ⊕ Enable button on the right.
Now every dead-key tilde is followed by a space. The "AZERTY tilde" ⊕ Remove button disables it.
Tested in Emacs with ns-option-modifier set to none, FireFox, iTerm and Terminal.