nix-darwin
nix-darwin copied to clipboard
Mac system hotkey customisation?
macOS defines a lot of useless hotkeys which may conflict with some apps (e.g. Spectacle and Alfred), so when I provision a new mac I have to remove some of them. This can be done through defaults write.
I used to have an ansible script for that, I guess something similar may be implemented in nix-darwin:
- https://github.com/7mind/mac-configurator/blob/master/roles/workstation/tasks/lib/settings.yml#L78
- https://github.com/7mind/mac-configurator/blob/master/configs/config-settings.yml#L153
This snippet just disables most of the hotkeys
{ lib, ... }: {
home.activation.disableHotkeys = let
hotkeys = [
10
11
118
12
13
15
16
160
162
163
17
175
179
18
19
190
20
21
22
222
23
24
25
26
27
32
33
34
35
36
37
52
57
59
60
61
65
7
79
8
80
81
82
9
98
];
disables = map (key:
"defaults write com.apple.symbolichotkeys AppleSymbolicHotKeys -dict-add ${
toString key
} '<dict><key>enabled</key><false/></dict>'") hotkeys;
in lib.hm.dag.entryAfter [ "writeBoundary" ] ''
# Disable hotkeys
echo >&2 "hotkey suppression..."
set -e
${lib.concatStringsSep "\n" disables}
'';
}
I'm new to nix but this is how I disabled Spotlight Search
system.defaults.CustomUserPreferences = {
"com.apple.symbolichotkeys" = {
AppleSymbolicHotKeys = {
# Disable 'Cmd + Space' for Spotlight Search
"64" = {
enabled = false;
};
# Disable 'Cmd + Alt + Space' for Finder search window
"65" = {
enabled = false;
};
};
};
};
@connorads unfortunately that setting seems to do nothing for me
hmm, it seems the system settings app needs to be closed for the setting to stick? I ran it a few times eventually it did apply
@connorads unfortunately that setting seems to do nothing for me hmm, it seems the system settings app needs to be closed for the setting to stick? I ran it a few times eventually it did apply
I think it worked first time for me. But I think I also added the below to my config early on which might be why.
system.activationScripts.postUserActivation.text = ''
# Following line should allow us to avoid a logout/login cycle when changing settings
/System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u
'';
I ran into the same problem. Ended up wrapping my solution into a tiny module here
I tried to make the module readable, and a bit nicer to work with by adding a README guide, inline comments, and enums (to explain the behavior of otherwise mystery numbers) e.g
let hotkeyEnums = {
moveFocusToMenuBar = 7; # Control-fn-F2
moveFocusToDock = 8; # Control-fn-F3
...
@connorads It looks like postUserActivation is no longer available . The alternative appears to be postActivation (found here). Full snippet:
system.activationScripts.postActivation.text = ''
# Following line should allow us to avoid a logout/login cycle when changing settings
sudo -u USERNAME_HERE /System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u
'';
I have added this script to my own module mentioned above as well.
Hope this helps anyone stumbling upon into this issue in the future :)
edit: corrected activationScript to run as a user
So by searching and testing I found that works well:
system.activationScripts.postActivation.text = ''
# Following line should allow us to avoid a logout/login cycle when changing settings
sudo -u yourname /System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u
'';
system.defaults.CustomUserPreferences = {
"com.apple.symbolichotkeys" = {
AppleSymbolicHotKeys = {
"60" = { enabled = false; };
"61" = { enabled = false; };
"64" = { enabled = false; };
"65" = { enabled = false; };
};
};
};
Thanks for all, who gave information. Thanks!
It would be awesome to have this incorporated into nix-darwin.
(I hate macos)
Here's my list of hotkeys I disable with what symbolic hot key they correlate to.
system.defaults = {
CustomUserPreferences = {
"com.apple.symbolichotkeys" = {
AppleSymbolicHotKeys = {
"60" = {
# Disable '^ + Space' for selecting the previous input source
enabled = false;
};
"61" = {
# Disable '^ + Option + Space' for selecting the next input source
enabled = false;
};
# Disable 'Cmd + Space' for Spotlight Search
"64" = {
enabled = false;
};
# Disable 'Cmd + Alt + Space' for Finder search window
"65" = {
# Set to false to disable
enabled = true;
};
};
};
};