Is it possible to toggle the setting for the F1, F2… keys behaving as function keys programatically or via some 3rd party software? I tried looking for the option in the .plist files for Preferences but could not find it.
You can use FNable.
FNable runs in the background and can quickly change your special keys to function keys. The applications that use Function keys, are remembered and everytime you switch to such an application, the function keys will be available. In all other apps the special keys will be available. Of cause you can still use the special keys while your function keys are active, just hold down the FN key when clicking the function keys.
I used to use an app called Palua which was much cheaper rather than that overpriced app, but the official website for it has disappeared and the app has been taken off the Mac App Store.
I ended up using Fluor. It’s free and open source and has a nice UI as well.