Add custom shortcuts to Fn hotkeys - profzei/Matebook-X-Pro-2018 GitHub Wiki
With the latest update and inclusion of SSDT-KBD.aml not only standard shortcuts for brightness and audio control are working but we are now able to reconfigure the shortcuts to custom settings.
This is the actual map for shortcuts:
- F1 brightness down
- F2 brightness up
- F4 audio mute/unmute
- F5 audio volume down
- F6 audio volume up
- F7 remapped as F16 (shortcut key for toggling microphone between mute and unmute)
- F9 remapped as F17 (shortcut key for toggling Wi-Fi device between on and off state)
- F10 remapped as F18 (shortcut key for Launchpad)
How to create a Workflow with Automator
- Open Automator via macOS’s Spotlight:
- Press:
⌘ + spacebar - Type:
Automator.appand pressEnter
- Press:
- Within the Automator menu bar, click on
Fileand selectNew
- Select
Quick Actionby clicking on the cog icon and then click theChoosebutton to get started
- Now you should see the
Quick Actionwizard:
- In the first drop-down, select
no input
- Now apply focus to the search bar inside of Automator. Here we will filter for the
Quick Actionwe need:- Click in the search bar
- Type:
Run Applescript
- Once you have filtered the Actions, double-click on
Run AppleScript
Script for toggling microphone between mute and unmute
- Inside of the AppleScript action, delete all of the default AppleScript
- Copy the following AppleScript to your Clipboard and paste it into the
Run AppleScriptaction within Automator
on getMicrophoneVolume()
input volume of (get volume settings)
end getMicrophoneVolume
on disableMicrophone()
set volume input volume 0
end disableMicrophone
on enableMicrophone()
set volume input volume 100
end enableMicrophone
if getMicrophoneVolume() is greater than 0 then
disableMicrophone()
else
enableMicrophone()
end if
- Save Your Automator Workflow:
- With Automator open, go to the Automator menu bar
- Click
Fileand then clickSave - The Save modal will open inside Automator. Save the workflow as
mic-toggleand clickSave
Script for toggling Wi-Fi device between on and off state
- Inside of the AppleScript action, replace
(* Your script goes here *)with the following contents:
set device to do shell script "networksetup -listallhardwareports | awk '$3==\"Wi-Fi\" {getline;print}' | awk '{print $2}'"
set power to do shell script "networksetup -getairportpower " & device & " | awk '{print $4}'"
if power is equal to "on" then
set power to "off"
else
set power to "on"
end if
do shell script ("networksetup -setairportpower " & device & " " & power)
- Save the Service
⌘ + S - Enter a proper name
wifi-togglefor the Service and clickSave
Granting Permissions to Automator
By default, Automator does not have permission to run actions. In order for mic-toggle or wifi-toggle to work correctly, we need to grant Automator access to do so.
- Open the
Security & PrivacySettings - Within
Security & Privacysettings, click on the lock icon located at the bottom-left of the modal window - Provide your credentials so you can allow changes to Automator’s permissions
- Once you have unlocked the
Security & Privacysettings, click on Accessibility from the selection box on the left side of the modal window
- Next, locate the
+sign under the selection box on the right side of theSecurity & Privacysettings modal and click it - Within the Finder modal that opens, navigate to the Applications directory
- Once there, locate Automator.app and click it
- Once Automator.app is selected, click the
Openbutton
- Validate that Automator shows up under the applications you want to allow to control your computer: Automator now has permission to run our AppleScript. Close that modal and lets create our keyboard shortcut.
Configuring the Keyboard Shortcuts
- Open the Keyboard Settings
- Once the Keyboard Settings modal opens, click the
Shortcutsbutton - In the left selection box, click
Services - In the right selection box, scroll down until you find
mic-toggle/wifi-toggle
- Add the Shortcut:
- Click on
mic-toggle/wifi-toggleservice from within the keyboard settings - Click the
Add Shortcutbutton - Press
F7/F9key respectively formic-toggleandwifi-toggle
- Test the integration: to test that it works, if you press the keyboard shortcut, you will see a cog icon in the macOS Menu Bar.
Assign a keyboard shortcut to Launchpad
Launchpad can be a powerful app launcher, but it requires that you move the cursor over to its icon in the Dock and click it to start. But you can assign a keyboard shortcut to do this.
- In
System Preferences->Keyboard->Shortcuts
- Choose
Launchpad & Dockon the left - Enable the
Launchpadshortcut clicking onShow Launchpad - Assign
F10hotkey.
That is it!
Credit to Jesse Riddle, @viktorklang and @profzei