iTranslated by AI
Putting Mac and Display to Sleep Instantly with the F6 Key
Requirements
There are several ways to put a Mac to sleep, but I wanted to do it with a single tap if possible.
Since I use a desktop Mac, I cannot use the method of closing the lid like on the MacBook series laptops. On the software side, macOS has a standard shortcut Option–Command–Eject (Eject or Touch ID key) to put the system to sleep. However, this key combination is a bit complex, and I wanted something more convenient. Also, I wanted a separate way to put only the display to sleep while keeping the system running.
- I want to achieve two things with my Mac:
- Put the system to sleep easily
- Put the display to sleep easily
- Execute immediately when I want to put it to sleep
- Don't want to use a mouse
- No complex operations like command input
- Don't rely on Siri or voice input
Assigning sleep to the F6 key with Karabiner-Elements

Why the F6 key? On Apple's Magic Keyboard, the F6 key has a moon symbol (🌙) engraved on it, and in macOS, it serves as a dedicated key for toggling "Do Not Disturb" mode. I rarely use Do Not Disturb, and since I operate it via the GUI when I do, I didn't mind assigning a different action to this key. Also, for the regular F-key functions, I can just combine it with the Fn key (or the Globe key 🌐), so there's no issue there. The fact that the moon symbol looks like "sleep" was also quite fitting.
Karabiner-Elements allows for complex key remapping, so I tried creating a custom "Complex Modification" for this.
I will create an empty JSON file at the following path and add the definitions. I will skip the explanation of how to use Karabiner-Elements itself, such as how to enable the definitions.
~/.config/karabiner/assets/complex_modifications/F-keys.json
Sleep display with F6 alone
This allows the display to be put to sleep when the F6 key is pressed by itself.
In the from field of the Complex Modification, I specify F6 and remap it to Control-Shift-Eject in the to field. Control-Shift-Eject is the macOS keyboard shortcut for putting the display to sleep.
{
"description": "F6 ▸ Sleep display",
"manipulators": [
{
"from": {
"key_code": "f6"
},
"to": [
{
"consumer_key_code": "eject",
"modifiers": [
"control",
"shift"
]
}
],
"type": "basic"
}
]
}
Put the system to sleep with Shift-F6
Since putting the system to sleep with a single tap of the F6 key is admittedly risky, I configured it to work with Shift-F6. I initially thought I could just add shift to the modifiers in the from section of the previous definition, but this did not work. This is because with a to remap, the sleep command is executed the moment the key is pressed, and the Mac reacts to the subsequent key-up event when you release the key, causing it to wake up immediately. (Even pressing it extremely quickly didn't work.)
So I considered whether I could execute the command on a key-up-like event or use delayed execution, and I eventually settled on the following method. This uses to_delayed_action instead of to to execute the command after a delay. While it obviously won't work if you press the keys very slowly, there was no problem with a slight time difference like tapping two keys.
The mapping is Option-Command-Eject, the standard macOS keyboard shortcut introduced at the beginning.
{
"description": "shift + F6 ▸ Sleep Mac",
"manipulators": [
{
"from": {
"key_code": "f6",
"modifiers": {
"mandatory": [
"shift"
]
}
},
"to_delayed_action": {
"to_if_invoked": [
{
"consumer_key_code": "eject",
"modifiers": [
"option",
"command"
]
}
]
},
"type": "basic"
}
]
}
Aside: Support for the Do Not Disturb Key
It seems that Karabiner-Elements cannot directly reference the Do Not Disturb key for technical reasons. While not directly related to this topic, if you want to remap Do Not Disturb to another key and continue using it, it seems best to use it in conjunction with the keyboard shortcut preferences in macOS System Settings.
References:
Discussion
M1Pro w/ Karabiner-Element14.13.0の当方の環境ではopt + cmd + ejectでは一瞬SleepするがすぐにWakeUpしてしまう。残念。
代わりにKarabiner-Elementで次のKey Eventを送るとSleepしてくれた。同時にScreen Lockが掛かるが今は目を瞑っている。
Lock Key on Magic Keyboard w/o Touch IDまた、software_function(iokit_power_management_sleep_system)を送る事でSystem Sleepさせる事が出来る事が次のLinkで紹介されてます。
iokit_power_management_sleep_system | Karabiner-Elements
これもやってみると確かにSleepしてくれるのだがWakeUp後に
Karabiner-MultiTouchExtensionが多重起動されてしまいました。厄介なので止めてしまいました。