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

  1. Open Automator via macOS’s Spotlight:
    • Press: ⌘ + spacebar
    • Type: Automator.app and press Enter
  2. Within the Automator menu bar, click on File and select New
  1. Select Quick Action by clicking on the cog icon and then click the Choose button to get started
  1. Now you should see the Quick Action wizard:
  1. In the first drop-down, select no input
  1. Now apply focus to the search bar inside of Automator. Here we will filter for the Quick Action we need:
    • Click in the search bar
    • Type: Run Applescript
  1. Once you have filtered the Actions, double-click on Run AppleScript

Script for toggling microphone between mute and unmute

  1. Inside of the AppleScript action, delete all of the default AppleScript
  1. Copy the following AppleScript to your Clipboard and paste it into the Run AppleScript action 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
  1. Save Your Automator Workflow:
  • With Automator open, go to the Automator menu bar
  • Click File and then click Save
  • The Save modal will open inside Automator. Save the workflow as mic-toggle and click Save

Script for toggling Wi-Fi device between on and off state

  1. 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)
  1. Save the Service ⌘ + S
  2. Enter a proper name wifi-toggle for the Service and click Save

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.

  1. Open the Security & Privacy Settings
  2. Within Security & Privacy settings, click on the lock icon located at the bottom-left of the modal window
  3. Provide your credentials so you can allow changes to Automator’s permissions
  4. Once you have unlocked the Security & Privacy settings, click on Accessibility from the selection box on the left side of the modal window
  1. Next, locate the + sign under the selection box on the right side of the Security & Privacy settings modal and click it
  2. 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 Open button
  1. 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

  1. Open the Keyboard Settings
  • Once the Keyboard Settings modal opens, click the Shortcuts button
  • In the left selection box, click Services
  • In the right selection box, scroll down until you find mic-toggle / wifi-toggle
  1. Add the Shortcut:
  • Click on mic-toggle / wifi-toggle service from within the keyboard settings
  • Click the Add Shortcut button
  • Press F7 / F9 key respectively for mic-toggle and wifi-toggle
  1. 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.

  1. In System Preferences -> Keyboard -> Shortcuts
  • Choose Launchpad & Dock on the left
  • Enable the Launchpad shortcut clicking on Show Launchpad
  • Assign F10 hotkey.

That is it!

Credit to Jesse Riddle, @viktorklang and @profzei