Script to change System Preference function key settings no longer working in Big Sur OS11 I have a simple script that I've used for years to toggle the function key (fn) off and on. The checkbox is located at System Preferences &gt; Keyboard &gt; Keyboard Tab &gt; 3rd checkbox down. Unfortunately, with OS11, it stopped working. I've now tweaked the script, but it generates an error message every other time I run it.
I'm a novice, so there may be a more elegant way to do this than the script below--it's simply what I've been using.
tell application &quot;System Preferences&quot;
    reveal anchor &quot;keyboardTab&quot; of pane &quot;com.apple.preference.keyboard&quot;
end tell
tell application &quot;System Events&quot;
    tell process &quot;System Preferences&quot;
        click checkbox &quot;Use F1, F2, etc. keys as standard function keys&quot; of tab group 1 of window 1
    end tell
end tell
quit application &quot;System Preferences&quot;

This is the Invalid Index error I get:

Weirdly, the script works when I remove the &lt;quit application &quot;system preferences&quot;&gt; line and run the script from Script Editor with System Preferences open (so I can watch what happens). When I close System Preferences and add back in the last line, &lt;quit application &quot;system preferences&quot;&gt;, here's the error I get within Script Editor:
error &quot;System Events got an error: Can’t get tab group 1 of window 1 of process &quot;System Preferences&quot;. Invalid index.&quot; number -1719 from tab group 1 of window 1 of process &quot;System Preferences&quot;
Any help or advice is greatly appreciated!
This AppleScript code works for me on Big Sur.
tell application &quot;System Preferences&quot;
    reveal anchor &quot;keyboardTab&quot; of pane &quot;com.apple.preference.keyboard&quot;
end tell
tell application &quot;System Events&quot;
    tell process &quot;System Preferences&quot;
        repeat until checkbox &quot;Use F1, F2, etc. keys as standard function keys on external keyboards&quot; of tab group 1 of window &quot;Keyboard&quot; exists
            delay 0.1
        end repeat
        click checkbox &quot;Use F1, F2, etc. keys as standard function keys on external keyboards&quot; of tab group 1 of window &quot;Keyboard&quot;
    end tell
end tell
quit application &quot;System Preferences&quot;

If that version throws errors… here is an alternate version that also works for me.
tell application &quot;System Preferences&quot;
    reveal anchor &quot;keyboardTab&quot; of pane &quot;com.apple.preference.keyboard&quot;
end tell
tell application &quot;System Events&quot; to tell process &quot;System Preferences&quot;
    repeat until checkbox 3 of tab group 1 of window &quot;Keyboard&quot; exists
        delay 0.1
    end repeat
    click checkbox 3 of tab group 1 of window &quot;Keyboard&quot;
end tell
quit application &quot;System Preferences&quot;