macos - 在 macOS Catalina 中使用 Applescript 切换 fn 键
问题描述
我正在尝试创建一个自动化快捷方式来切换触控栏中的 fn 键。
到目前为止,这是我的方法:
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preference.keyboard"
//TO-DO: script that opens drop down menu in settings and changes it to display fn buttons
end tell
解决方案
对于其他试图完成这项工作的人 - 我终于得到了我的解决方案。测试: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
希望有人觉得它有用!西蒙。
推荐阅读
- centos7 - 使用过多 CPU 的脉冲音频
- java - 如何使用现有片段模板扩展 Thymeleaf 方言
- python - 如果给出了 id,我如何在这个列表中找到其他属性的其他值,里面有字典
- networking - 当您有本地 IP 地址时,为什么我们需要 MAC 地址
- r - 如何在 R 中的单个数据框中转换(标准化)类别内的数据?
- java - 春季启动中的@value没有从application.properties中提供价值
- arrays - 如何编写动态数量的行并将它们分配给 C 中的数组
- c - 整数 x; 是句法错误还是语义错误?
- python - 计算给定掩码中两个 numpy 数组中相等元素的数量
- sql - PostgreSQL - 计算出售计数的机构数量