Toggle "Use all F1, F2 as standard keys" via script
tell application "System Preferences"
    reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
tell application "System Events" to tell process "System Preferences"
    click checkbox 1 of tab group 1 of window 1
end tell
quit application "System Preferences"


You could also use defaults write -g com.apple.keyboard.fnState -bool true, but I don't know any way to apply the changes without logging out and back in again.