我几乎从不使用 MacBook Pro 上的功能键。我主要只是将它们用于音量、亮度等。现在我已经开始玩《星际争霸 2》了,我想在不按下 fn 键的情况下使用它们。
我想编写一个小 shell 脚本来翻转“使用所有 F1、F2 等键作为标准功能键”复选框。我想我可以使用默认命令来更改它,但我不确定要使用什么值。这样我就不必每次想玩时都更改首选项。我只需运行脚本即可切换按键,甚至启动游戏。
有什么想法吗?
I hardly ever use the function keys on my macbook pro. I mostly just use them for volume, brightness, etc. Now that I've started playing Starcraft 2 a bunch, I want to use them without having to press the fn key down.
I want to write a little shell script that will flip the "Use all F1, F2, etc keys as standard function keys" check box. I was thinking I could use the defaults command to change it but I wasn't sure what values to use. This way I don't have to change the the preferences every time I want to play. I can just run the script that'll switch the keys and even launch the game.
Any ideas?
发布评论
评论(6)
一个可以解决这个问题的 AppleScript —— 取自 http://scriptbuilders.net/files/fn1。 1.html,略有修改
在MacOS 10.6.4上测试
An AppleScript that should do the trick -- taken from http://scriptbuilders.net/files/fn1.1.html, with slight modifications
Tested on MacOS 10.6.4
该命令是
defaults write -g com.apple.keyboard.fnState
,尽管我过去在更改它时遇到了问题。我最终只使用了 AppleScript。尝试一下。编辑
详细说明,我遇到的问题是实际值已更改,但它不会主动更改系统偏好设置中的设置,也不会切换 fnState,因为该文件是仅在启动/登录等时读取。此外,对另一个任务打开的配置文件进行更改听起来是损坏文件的好方法。
The command is
defaults write -g com.apple.keyboard.fnState
, although I've had problems in the past changing it. I ended up just using an AppleScript. Give it a try.Edit
To elaborate, the problems I've had is that the actual value is changed, but it doesn't actively change the setting in System Preferences nor does the fnState toggle, because the file is only read at boot/login etc. Also, making changes to a config file that's opened by another task sounds like a good way to corrupt the file.
您可以安装很棒的 Karabiner-Elements。
在系统偏好设置下->键盘首选项,确保选中“使用所有 F1、F2 等键作为标准功能键”作为必要条件。
You can install the awsome Karabiner-Elements.
Under System Preferences-> Keyboard preferences, make sure "Use all F1, F2, etc. keys as standard function keys" is checked as a perquisites.
对于任何其他试图让这项工作发挥作用的人来说——我终于找到了可行的解决方案。测试环境:MacOS Big Sur,11.4,2021 年 6 月。
代码基于此处:
https://github.com/MrSimonC/Toggle-Mac-Function-Keys
但为了简洁起见,这里是苹果脚本文件的内容:
希望有人发现它有用!
For anyone else trying to make this work - I've finally gotten my solution to work. Tested with: MacOS Big Sur, 11.4, June 2021.
The code is based here:
https://github.com/MrSimonC/Toggle-Mac-Function-Keys
but for brevity, here is the contents of the apple script file:
Hope someone finds it useful!
感谢@simonc的回答,可以轻松地将它与光线投射一起使用。
如果有人想要通过终端运行该功能:
将以下脚本保存为 sh 文件,例如:toggle-fn.sh
使用
sh toggle-fn.sh 在终端上运行
或者如果有人使用 raycast 并希望通过其命令功能拥有此功能:
Thanks to @simonc's answer, easily using it with raycast.
If anybody wants to have the functionality to be run through terminal:
save below script as an sh file, eg: toggle-fn.sh
run on terminal using
sh toggle-fn.sh
Or if anyone is using raycast and want to have this functionality through its command functionality:
note: for raycast to be able to run the shell command that requires accessibility permissions, you have to first give access to raycast on accessibility through
system settings > privacy and security > accessibility
以下是 @Beytan 脚本的变体(仅适用于 MacOS Sonoma!),这样您可以提供一个命令行参数来以绝对方式确定您是否希望 F1..F12 键打开或关闭,而不管它们当前的状态如何状态,即它将在单击之前检查状态。
将以下内容保存为
setfn.sh
并运行chmod +x setfn.sh
然后您可以执行setfn.sh on
来获得 F1.. F12 可以激活 dosbox 应用程序等,或者setfn.sh off
可以使用 MacOS 默认值,即音量、亮度等。the following is a variation of @Beytan's script (for MacOS Sonoma only!) such that you can provide a command-line argument to determine in an absolute manner if you want the F1..F12 keys to be on or off regardless of their current status i.e. it will check the status prior to clicking.
save the following as
setfn.sh
and runchmod +x setfn.sh
then you can executesetfn.sh on
to have the F1..F12 be activated for dosbox applications etc orsetfn.sh off
to have the MacOS default which is volume, brightness, etc.