我知道您可以在“系统偏好设置”屏幕中的“键盘”中打开或关闭此选项,但我想知道是否可以通过快捷方式执行此操作,因为我一直这样做。
答案1
为了使以下工作正常进行,您需要启用辅助设备访问在系统偏好设置 » 通用访问。
打开 Automator,选择服务并选择服务接收没有输入(靠近顶部)。
双击运行 AppleScript在里面实用工具库的类别。将新创建的操作的默认代码片段替换为以下内容:
tell application "System Preferences"
set current pane to pane id "com.apple.preference.keyboard"
tell application "System Events"
tell process "System Preferences"
click checkbox "Use all F1, F2, etc. keys as standard function keys" of tab group 1 of window "Keyboard"
end tell
end tell
quit
end tell
系统偏好设置将启动,但它不会显示,并且在切换设置后将立即退出。
按下Command-S
保存,并命名,例如切换 Fn。 结果:
去系统偏好设置 » 键盘 » 键盘快捷键 » 服务为此服务分配键盘快捷键。
答案2
我知道这篇文章已经过时了,但我无法让上面的代码在 Mountinan Lion 上运行。我找到了一个类似的代码片段,但删除了一些不必要的部分。
tell application "System Preferences"
set current pane to pane "com.apple.preference.keyboard"
end tell
tell application "System Events"
-- If we don't have UI Elements enabled, then nothing is really going to work.
if UI elements enabled then
tell application process "System Preferences"
get properties
click radio button "Keyboard" of tab group 1 of window "Keyboard"
click checkbox "Use all F1, F2, etc. keys as standard function keys" of tab group 1 of window "Keyboard"
end tell
tell application "System Preferences" to quit
else
-- GUI scripting not enabled. Display an alert
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
display dialog "UI element scripting is not enabled. Please activate \"Enable access for assistive devices\""
end tell
end if
end tell
希望这可以帮助
答案3
对于其他试图实现这一点的人 - 我终于找到了解决方案。测试系统:MacOS Big Sur,11.4,2021 年 6 月。
代码基于此处: https://github.com/MrSimonC/Toggle-Mac-Function-Keys
但为了简洁起见,这里是苹果脚本文件的内容:
-- Apple Script (i.e. Use in Apple's Script Editor Application) to Toggle Function Keys / Media keys on/off
-- Tested on MacOS Big Sur (11.4) June 2021
-- Project Path: https://github.com/MrSimonC/Toggle-Mac-Function-Keys
tell application "System Preferences"
set current pane to pane "com.apple.preference.keyboard"
end tell
tell application "System Events"
if UI elements enabled then
tell application process "System Preferences"
repeat until exists tab group 1 of window "Keyboard"
delay 0.5
end repeat
click radio button "Keyboard" of tab group 1 of window "Keyboard"
click checkbox "Use F1, F2, etc. keys as standard function keys" of tab group 1 of window "Keyboard"
end tell
tell application "System Preferences" to quit
else
-- GUI scripting not enabled. Display an alert
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.security"
display dialog "UI element scripting is not enabled. Please activate this app under Privacy -> Accessibility so it can access the settings it needs."
end tell
end if
end tell
希望有人觉得它有用!西蒙。
答案4
您还可以使用私有文件与 KeyRemap4MacBook 类似:
<?xml version="1.0"?>
<root>
<item>
<name>test</name>
<identifier>test</identifier>
<autogen>__KeyToKey__ KeyCode::F1, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_CONFIG_TOGGLE_fn</autogen>
<autogen>__KeyToKey__ KeyCode::BRIGHTNESS_DOWN, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_CONFIG_TOGGLE_fn</autogen>
</item>
<item>
<name>fn</name>
<identifier vk_config="true">fn</identifier>
<autogen>__KeyToKey__ KeyCode::BRIGHTNESS_DOWN, KeyCode::F1</autogen>
<autogen>__KeyToKey__ KeyCode::BRIGHTNESS_UP, KeyCode::F2</autogen>
<autogen>__KeyToKey__ KeyCode::EXPOSE_ALL, KeyCode::F3</autogen>
<autogen>__KeyToKey__ KeyCode::LAUNCHPAD, KeyCode::F4</autogen>
<autogen>__ConsumerToKey__ ConsumerKeyCode::KEYBOARDLIGHT_LOW, KeyCode::F5</autogen>
<autogen>__ConsumerToKey__ ConsumerKeyCode::KEYBOARDLIGHT_HIGH, KeyCode::F6</autogen>
<autogen>__ConsumerToKey__ ConsumerKeyCode::MUSIC_PREV, KeyCode::F7</autogen>
<autogen>__ConsumerToKey__ ConsumerKeyCode::MUSIC_PLAY, KeyCode::F8</autogen>
<autogen>__ConsumerToKey__ ConsumerKeyCode::MUSIC_NEXT, KeyCode::F9</autogen>
<autogen>__ConsumerToKey__ ConsumerKeyCode::VOLUME_MUTE, KeyCode::F10</autogen>
<autogen>__ConsumerToKey__ ConsumerKeyCode::VOLUME_DOWN, KeyCode::F11</autogen>
<autogen>__ConsumerToKey__ ConsumerKeyCode::VOLUME_UP, KeyCode::F12</autogen>
<autogen>__KeyToKey__ KeyCode::F1, KeyCode::BRIGHTNESS_DOWN</autogen>
<autogen>__KeyToKey__ KeyCode::F2, KeyCode::BRIGHTNESS_UP</autogen>
<autogen>__KeyToKey__ KeyCode::F3, KeyCode::EXPOSE_ALL</autogen>
<autogen>__KeyToKey__ KeyCode::F4, KeyCode::LAUNCHPAD</autogen>
<autogen>__ConsumerToKey__ KeyCode::F5, ConsumerKeyCode::KEYBOARDLIGHT_LOW</autogen>
<autogen>__ConsumerToKey__ KeyCode::F6, ConsumerKeyCode::KEYBOARDLIGHT_HIGH</autogen>
<autogen>__ConsumerToKey__ KeyCode::F7, ConsumerKeyCode::MUSIC_PREV</autogen>
<autogen>__ConsumerToKey__ KeyCode::F8, ConsumerKeyCode::MUSIC_PLAY</autogen>
<autogen>__ConsumerToKey__ KeyCode::F9, ConsumerKeyCode::MUSIC_NEXT</autogen>
<autogen>__ConsumerToKey__ KeyCode::F10, ConsumerKeyCode::VOLUME_MUTE</autogen>
<autogen>__ConsumerToKey__ KeyCode::F11, ConsumerKeyCode::VOLUME_DOWN</autogen>
<autogen>__ConsumerToKey__ KeyCode::F12, ConsumerKeyCode::VOLUME_UP</autogen>
</item>
</root>