Mac OS X Safari 6默认搜索引擎在可能的值之间切换

Inf*_*ies 5 safari cocoa osx-mountain-lion safari6

我想在Mac OS X上以编程方式更改Safari默认搜索引擎.我知道有3个可能的值,但Safari存储当前值的位置?我想从Cocoa代码中将Google更改为Yahoo.可能吗?

我在文件中看到一个SearchProviderIdentifierMigratedToSystemPreference变量设置为YES com.apple.Safari.plist,可以找到~/Library/Preferences.这可能是当前值的关键,但存储了"系统偏好"的位置?你有任何线索吗?


更新:我发现此命令defaults read -g NSPreferredWebServices始终返回所选的默认搜索引擎.这个问题是,当我更改它的值时,safari不会更改该值.
这是将值更改为Bing的命令:
defaults write -g NSPreferredWebServices '{NSWebServicesProviderWebSearch = { NSDefaultDisplayName = Bing; NSProviderIdentifier = "com.bing.www"; }; }';

该命令应在终端中执行.

Fri*_*lab 1

显然(使用 macOS 11.5 进行测试),NSPreferredWebServices设置了系统搜索引擎(例如,当使用 Spotlight 启动网络搜索时,Spotlight 会重定向您)。
\n只要 Safari\xe2\x80\x99s 搜索引擎更新,此密钥就会更新。

\n

当 Safari\xe2\x80\x99s 搜索引擎更改时,另一个密钥也会更新:(SearchProviderShortName在域中com.apple.Safari)。显然这是要更新以更改 Safari\xe2\x80\x99s 搜索引擎的版本。DuckDuckGo(例如设置为使用 DuckDuckGo。)

\n

以前(在 之前SearchProviderIdentifierMigratedToSystemPreference),键是SearchProviderIdentifier,值com.duckduckgo是 DuckDuckGo 搜索引擎。

\n

我的建议是将它们全部设置为安全:

\n
defaults write -g NSPreferredWebServices \'{NSWebServicesProviderWebSearch = { NSDefaultDisplayName = Bing; NSProviderIdentifier = "com.bing.www"; }; }\'\ndefaults write com.apple.Safari SearchProviderIdentifier -string com.bing.www\ndefaults write com.apple.Safari SearchProviderShortName -string Bing\n
Run Code Online (Sandbox Code Playgroud)\n
\n

相关问题:/sf/answers/1135707051/

\n