Можете ли вы включить / выключить функциональные клавиши с помощью сочетания клавиш на OSX?

4951
Ben Waine

Я знаю, что вы можете включать и выключать эту опцию на экране «Системные настройки» для «клавиатуры», но я хотел бы знать, могу ли я сделать это с помощью ярлыка, как я делаю это все время.

7

3 ответа на вопрос

9
Daniel Beck

To make the following work, you need to Enable access for assistive devices in System Preferences » Universal Access.


Open Automator, select Service and choose that the service receives no input (near the top).

Double-click Run AppleScript in the Utilities category of the library. Replace the default code snippet of the newly created action with the following:

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 

System Preferences will launch, but it will not be displayed and will quit immediately after toggling the setting.

Press Command-S to save, give it the name e.g. Toggle Fn. Result:

enter image description here


Go to System Preferences » Keyboard » Keyboard Shortcuts » Services to assign a keyboard shortcut for this Service.

Если при выполнении этой команды системные настройки уже запущены, она завершится. Код для предотвращения этого раздул бы этот ответ. Daniel Beck 13 лет назад 1
Вопрос помечен как osx-snow-leopard, который, похоже, требует этот ответ. Я не думаю, что смогу сделать сервис в OS X 10.5, судя по тому, что я вижу перед собой, по сравнению с http://gigaom.com/apple/quick-tip-automator-and-services-in-snow- леопард / Philip Durbin 13 лет назад 0
@Philip Я не помню, как службы работали в 10.5, но созданная Automator служба - это всего лишь рабочий процесс Automator, сохраненный в `~ / Library / Services`. Может быть, вы можете повторить это вручную? Чтобы настроить меню «Сервисы», используйте ServiceScrubber. Daniel Beck 13 лет назад 0
это работает на 10.6, но по какой-то причине мой ярлык на клавиатуре продолжал давать сбой или срабатывал, когда я этого не хотел. поэтому я перешел на вызов из командной строки с osascript на основе http://stackoverflow.com/questions/3446128/enable-disable-fn-keys-from-the-command-line-on-the-mac Philip Durbin 12 лет назад 0
@Philip Вы всегда можете включить меню AppleScript и сохранить код в виде файла `scpt` в` ~ / Library / Scripts` и вызывать из строки меню. Используя сторонние FastScripts, вы можете назначить сочетание клавиш. Daniel Beck 12 лет назад 0
Полностью забытый, я написал этот вопрос. Регуглировал и нашел ваше решение. Отлично, спасибо! Ben Waine 11 лет назад 0
Я использую комбинацию сценария оболочки и AppleScript и переключаю состояние через Keyboard Maestro. Таким образом, я также могу иметь правила для каждого приложения, см. В Adobe Suite. Смотрите: http://rocketink.net/2013/06/toggle-function-keys.html pattulus 10 лет назад 0
Я использую Controllermate и использовал этот скрипт в сочетании с кнопкой EJECT (у меня удален привод DVD), и он отлично работал в ElCap! Отличный материал, спасибо! Madivad 7 лет назад 0
4
pechar

Я знаю, что это сообщение старое, но я не смог заставить вышеописанное работать на 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 

Надеюсь это поможет

0
user495470

Вы также можете использовать файл private.xml вот так с 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> 

См. Источник для значений кода ключа и предопределенных настроек .