![从命令行删除 OSX 聚光灯键盘快捷键](https://linux22.com/image/1530641/%E4%BB%8E%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%88%A0%E9%99%A4%20OSX%20%E8%81%9A%E5%85%89%E7%81%AF%E9%94%AE%E7%9B%98%E5%BF%AB%E6%8D%B7%E9%94%AE.png)
答案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。