Cocoa 按钮打开系统偏好设置页面
在 OSX Cocoa 应用程序中,我想要一个可以打开“语音”首选项窗格的按钮。这可能吗?我只是想节省他们的时间去“系统偏好设置”>“演讲>文字转语音
In a OSX Cocoa app, I would like a button that would open the "speech" preference pane. Is that possible? I'm just trying to save them the time to go System Preferences > Speech > Text to Speech
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
人们甚至可以在首选项窗格中选择特定的子项目。
以下是在“隐私”窗格下选择“相机”的示例:
部分功劳归功于以下站点:https://macosxautomation .com/system-prefs-links.html
供参考的 URL 列表(*针对 macOS Big Sur 和 Catalina 和 Mojave 进行了更新):
所有这一切都可以通过键入来实现PreferencePane 中的 Info.plist + System Preferences.app 中的 CFBundleURLTypes (CFBundleURLSchemes) x-apple.systempreferences (Info.plist)
自 10.15 起,部分密钥位于 PrivacyTCCServices.plist (Security.prefPane) 中
自 10.14 Mojave 起,部分隐私密钥已不再存在。 Mojave 隐私列表:
Catalina 隐私列表:
One can even select specific sub item inside a pref pane.
Here is example to select Camera under Privacy pane:
Some credit goes to following site: https://macosxautomation.com/system-prefs-links.html
List of URLs for reference (*updated for macOS Big Sur & Catalina & Mojave):
All this is possible thanks to key in Info.plist in preferencePane + CFBundleURLTypes (CFBundleURLSchemes) x-apple.systempreferences (Info.plist) in System Preferences.app
As of 10.15 some of the keys are located in PrivacyTCCServices.plist (Security.prefPane)
As of 10.14 Mojave some Privacy keys ceased to exists. Mojave privacy list:
Catalina privacy list:
以下是一种相当简单(且可靠)的方法,至少可以将系统偏好设置打开到 Speech.prefPane:
但是,它不一定会切换到“文本到语音”选项卡,而是切换到“文本到语音”选项卡。用户选择的最后一个选项卡。
实际上也可以切换到“文本转语音”选项卡,但涉及的范围更广一些。您可以使用 AppleScript 将命令发送到系统偏好设置应用程序,但要使用 ScriptingBridge.framework(请参阅 Scripting Bridge 编程指南)速度要快得多。
您需要将 ScriptingBridge.framework 添加到项目中,然后在终端中使用如下命令生成要使用的 SBSystemPreferences.h 头文件:
sdef“/Applications/System Preferences.app”| sdp -fh --basename SBSystemPreferences -o ~/Desktop/SBSystemPreferences.h
将
SBSystemPreferences.h
标头添加到您的项目中,然后将-openSpeechPrefs:
更改为以下:编辑:
使用 ScriptingBridge.framework 方法的示例项目:
http://github.com/NSGod/OpenSystemPrefsTTS
The following is a fairly easy (and reliable) way to at least get System Preferences open to the Speech.prefPane:
However, it won't necessarily be switched to the
Text to Speech
tab, but rather the last tab the user had selected.It is possible to actually switch to the Text to Speech tab as well, but it's a bit more involved. You can use AppleScript to send commands to the System Preferences application, but using the
ScriptingBridge.framework
(See Scripting Bridge Programming Guide) is much faster.You'll need to add the
ScriptingBridge.framework
to your project, and then use a command like the following in Terminal to generate aSBSystemPreferences.h
header file to work with:sdef "/Applications/System Preferences.app" | sdp -fh --basename SBSystemPreferences -o ~/Desktop/SBSystemPreferences.h
Add that
SBSystemPreferences.h
header to your project, then change-openSpeechPrefs:
to the following:EDIT:
Sample project using the ScriptingBridge.framework method:
http://github.com/NSGod/OpenSystemPrefsTTS
对于遇到我在评论中提到的相同问题的人,只需转到
~/Desktop
(因为我指定了这个位置),您就会看到SBSystemPreferences.h< /代码> 已创建。
但是,在此标头中缺少一些类声明。因此,您必须显式添加此声明。
就我而言,类“item”未定义。所以添加这个:
@class SBSystemPreferencesItem;
然后编译一下,看看还缺少什么,需要添加哪些声明。
For the guys who run into the same issue that I mentioned in the comment, just go to the
~/Desktop
(cos I specify this position) and you'll see theSBSystemPreferences.h
has been created.However, in this header, some class declarations are missing. So you have to add this declarations explicitly.
In my case, class "item" is undefined. So add this:
@class SBSystemPreferencesItem;
Then compile it and see what's still missing, which declaration needs to be added.