从命令行删除 OSX 聚光灯键盘快捷键

从命令行删除 OSX 聚光灯键盘快捷键

如何在不使用系统偏好设置的情况下禁用键盘快捷键Cmd+ ?Space

我已经找到了但它并没有真正的帮助,因为我既不知道密钥也不知道如何将其设置为禁用。

有人能帮助我吗?

答案1

接受的答案不适用于全新安装,因为在用户单击 UI 之前,该Dict条目并不存在。AppleSymbolicHotKeys:64

就我而言,我尝试使用它PlistBuddy来编写 macOS 安装脚本。要求没有 UI 交互。

PlistBuddy -help我在输出中寻找解决方案

Command Format:
    Help - Prints this information
    Exit - Exits the program, changes are not saved to the file
    Save - Saves the current changes to the file
    Revert - Reloads the last saved version of the file
    Clear [<Type>] - Clears out all existing entries, and creates root of Type
    Print [<Entry>] - Prints value of Entry.  Otherwise, prints file
    Set <Entry> <Value> - Sets the value at Entry to Value
    Add <Entry> <Type> [<Value>] - Adds Entry to the plist, with value Value
    Copy <EntrySrc> <EntryDst> - Copies the EntrySrc property to EntryDst
    Delete <Entry> - Deletes Entry from the plist
    Merge <file.plist> [<Entry>] - Adds the contents of file.plist to Entry
    Import <Entry> <file> - Creates or sets Entry the contents of file

Entry Format:
    Entries consist of property key names delimited by colons.  Array items
    are specified by a zero-based integer index.  Examples:
        :CFBundleShortVersionString
        :CFBundleDocumentTypes:2:CFBundleTypeExtensions

Types:
    string
    array
    dict
    bool
    real
    integer
    date
    data

Examples:
    Set :CFBundleIdentifier com.apple.plistbuddy
        Sets the CFBundleIdentifier property to com.apple.plistbuddy
    Add :CFBundleGetInfoString string "App version 1.0.1"
        Adds the CFBundleGetInfoString property to the plist
    Add :CFBundleDocumentTypes: dict
        Adds a new item of type dict to the CFBundleDocumentTypes array
    Add :CFBundleDocumentTypes:0 dict
        Adds the new item to the beginning of the array
    Delete :CFBundleDocumentTypes:0 dict
        Deletes the FIRST item in the array
    Delete :CFBundleDocumentTypes
        Deletes the ENTIRE CFBundleDocumentTypes array

这是我的解决方案:

/usr/libexec/PlistBuddy ~/Library/Preferences/com.apple.symbolichotkeys.plist -c \
  "Add :AppleSymbolicHotKeys:64:enabled bool false"

如果key已经存在,PlistBuddy则会打印出以下错误:

Add: ":AppleSymbolicHotKeys:64:enabled" Entry Already Exists

您必须先删除该条目:

/usr/libexec/PlistBuddy ~/Library/Preferences/com.apple.symbolichotkeys.plist -c \
  "Delete :AppleSymbolicHotKeys:64"

我的完整脚本"Show Spotlight search"禁用"Show Finder search window"macOS Monterey

#!/bin/bash

set -e

# target output for AppleSymbolicHotKeys:64
#
# <key>64</key>
# <dict>
#   <key>enabled</key>
#   <false/>
#   <key>value</key>
#   <dict>
#     <key>parameters</key>
#     <array>
#       <integer>65535</integer>
#       <integer>49</integer>
#       <integer>1048576</integer>
#     </array>
#     <key>type</key>
#     <string>standard</string>
#   </dict>
# </dict>

/usr/libexec/PlistBuddy ~/Library/Preferences/com.apple.symbolichotkeys.plist \
  -c "Delete :AppleSymbolicHotKeys:64" \
  -c "Add :AppleSymbolicHotKeys:64:enabled bool false" \
  -c "Add :AppleSymbolicHotKeys:64:value:parameters array" \
  -c "Add :AppleSymbolicHotKeys:64:value:parameters: integer 65535" \
  -c "Add :AppleSymbolicHotKeys:64:value:parameters: integer 49" \
  -c "Add :AppleSymbolicHotKeys:64:value:parameters: integer 1048576" \
  -c "Add :AppleSymbolicHotKeys:64:type string standard"

# target output for AppleSymbolicHotKeys:65
#
# <key>65</key>
# <dict>
#   <key>enabled</key>
#   <false/>
#   <key>value</key>
#   <dict>
#     <key>parameters</key>
#     <array>
#       <integer>65535</integer>
#       <integer>49</integer>
#       <integer>1572864</integer>
#     </array>
#     <key>type</key>
#     <string>standard</string>
#   </dict>
# </dict>

/usr/libexec/PlistBuddy ~/Library/Preferences/com.apple.symbolichotkeys.plist \
  -c "Delete :AppleSymbolicHotKeys:65" \
  -c "Add :AppleSymbolicHotKeys:65:enabled bool false" \
  -c "Add :AppleSymbolicHotKeys:65:value:parameters array" \
  -c "Add :AppleSymbolicHotKeys:65:value:parameters: integer 65535" \
  -c "Add :AppleSymbolicHotKeys:65:value:parameters: integer 49" \
  -c "Add :AppleSymbolicHotKeys:65:value:parameters: integer 1572864" \
  -c "Add :AppleSymbolicHotKeys:65:type string standard"

PS 更改需要完全重启操作系统,我还没有找到解决这个问题的方法。

答案2

Spotlight 键盘快捷键存储在 中com.apple.symbolichotkeys

要禁用它,请运行以下命令:

/usr/libexec/PlistBuddy ~/Library/Preferences/com.apple.symbolichotkeys.plist -c \
  "Set AppleSymbolicHotKeys:64:enabled false"

退出后生效。

要重新启用,请将 false 替换为 true。

相关内容