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.app
and pressEnter
- Press:
- Within the Automator menu bar, click on
File
and selectNew
- Select
Quick Action
by clicking on the cog icon and then click theChoose
button to get started
- Now you should see the
Quick Action
wizard:
- 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 Action
we 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 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
- Save Your Automator Workflow:
- With Automator open, go to the Automator menu bar
- Click
File
and then clickSave
- The Save modal will open inside Automator. Save the workflow as
mic-toggle
and 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-toggle
for 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 & Privacy
Settings - Within
Security & Privacy
settings, 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 & Privacy
settings, 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 & Privacy
settings 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
Open
button
- 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
Shortcuts
button - 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-toggle
service from within the keyboard settings - Click the
Add Shortcut
button - Press
F7
/F9
key respectively formic-toggle
andwifi-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 & Dock
on the left - Enable the
Launchpad
shortcut clicking onShow Launchpad
- Assign
F10
hotkey.
That is it!
Credit to Jesse Riddle, @viktorklang and @profzei