Trong ứng dụng Cocoa OSX, tôi muốn nút có thể mở ngăn tùy chọn "lời nói". Điều đó có thể không? Tôi chỉ cố gắng tiết kiệm cho họ thời gian để đi System Preferences> Speech> Text to SpeechNút ca cao sẽ mở trang Tùy chọn hệ thống
Trả lời
Sau đây là cách khá dễ dàng (và đáng tin cậy) để ít nhất có được Tùy chọn hệ thống mở cho Speech.prefPane:
- (IBAction)openSpeechPrefs:(id)sender {
[[NSWorkspace sharedWorkspace] openURL:
[NSURL fileURLWithPath:@"/System/Library/PreferencePanes/Speech.prefPane"]];
}
Tuy nhiên, nó không nhất thiết phải được chuyển sang tab Text to Speech
, mà là tab cuối cùng mà người dùng đã chọn.
Có thể thực sự chuyển sang tab Văn bản thành giọng nói, nhưng có liên quan nhiều hơn một chút. Bạn có thể sử dụng AppleScript để gửi lệnh đến ứng dụng Tùy chọn hệ thống, nhưng sử dụng ScriptingBridge.framework
(Xem Scripting Bridge Programming Guide) sẽ nhanh hơn nhiều.
Bạn sẽ cần phải thêm ScriptingBridge.framework
để dự án của bạn, và sau đó sử dụng một lệnh như sau trong Terminal để tạo ra một tập tin SBSystemPreferences.h
tiêu đề làm việc với:
sdef "/Applications/System Preferences.app" | sdp -fh --basename SBSystemPreferences -o ~/Desktop/SBSystemPreferences.h
Thêm vào đó SBSystemPreferences.h
tiêu đề để dự án của bạn, sau đó thay đổi -openSpeechPrefs:
như sau:
- (IBAction)openSpeechPrefs:(id)sender {
SBSystemPreferencesApplication *systemPrefs =
[SBApplication applicationWithBundleIdentifier:@"com.apple.systempreferences"];
[systemPrefs activate];
SBElementArray *panes = [systemPrefs panes];
SBSystemPreferencesPane *speechPane = nil;
for (SBSystemPreferencesPane *pane in panes) {
if ([[pane id] isEqualToString:@"com.apple.preference.speech"]) {
speechPane = pane;
break;
}
}
[systemPrefs setCurrentPane:speechPane];
SBElementArray *anchors = [speechPane anchors];
for (SBSystemPreferencesAnchor *anchor in anchors) {
if ([anchor.name isEqualToString:@"TTS"]) {
[anchor reveal];
}
}
}
EDIT:
dự án mẫu sử dụng phương pháp ScriptingBridge.framework: http://github.com/NSGod/OpenSystemPrefsTTS
Đối với những kẻ đã chạy vào cùng một vấn đề mà tôi đã đề cập trong các bình luận, chỉ cần đi đến ~/Desktop
(cos tôi chỉ định vị trí này) và bạn sẽ thấy các SBSystemPreferences.h
đã được tạo.
Tuy nhiên, trong tiêu đề này, một số khai báo lớp bị thiếu. Vì vậy, bạn phải thêm các khai báo này một cách rõ ràng.
Trong trường hợp của tôi, lớp "mục" chưa được xác định. Vì vậy, hãy thêm điều này: @class SBSystemPreferencesItem;
Sau đó, biên dịch và xem nội dung nào còn thiếu, khai báo nào cần được thêm vào.
NSURL *URL = [NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.speech?TTS"];
[[NSWorkspace sharedWorkspace] openURL:URL];
Tín đi vào trang web sau đây: https://macosxautomation.com/system-prefs-links.html
Danh sách các URL để tham khảo:
Accessibility Preference Pane
Main x-apple.systempreferences:com.apple.preference.universalaccess
Display x-apple.systempreferences:com.apple.preference.universalaccess?Seeing_Display
Zoom x-apple.systempreferences:com.apple.preference.universalaccess?Seeing_Zoom
VoiceOver x-apple.systempreferences:com.apple.preference.universalaccess?Seeing_VoiceOver
Descriptions x-apple.systempreferences:com.apple.preference.universalaccess?Media_Descriptions
Captions x-apple.systempreferences:com.apple.preference.universalaccess?Captioning
Audio x-apple.systempreferences:com.apple.preference.universalaccess?Hearing
Keyboard x-apple.systempreferences:com.apple.preference.universalaccess?Keyboard
Mouse & Trackpad x-apple.systempreferences:com.apple.preference.universalaccess?Mouse
Switch Control x-apple.systempreferences:com.apple.preference.universalaccess?Switch
Dictation x-apple.systempreferences:com.apple.preference.universalaccess?SpeakableItems
Security & Privacy Preference Pane
Main x-apple.systempreferences:com.apple.preference.security
General x-apple.systempreferences:com.apple.preference.security?General
FileVault x-apple.systempreferences:com.apple.preference.security?FDE
Firewall x-apple.systempreferences:com.apple.preference.security?Firewall
Advanced x-apple.systempreferences:com.apple.preference.security?Advanced
Privacy x-apple.systempreferences:com.apple.preference.security?Privacy
Privacy-Accessibility x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility
Privacy-Assistive x-apple.systempreferences:com.apple.preference.security?Privacy_Assistive
Privacy-Location Services x-apple.systempreferences:com.apple.preference.security?Privacy_LocationServices
Privacy-Contacts x-apple.systempreferences:com.apple.preference.security?Privacy_Contacts
Privacy-Diagnostics & Usage x-apple.systempreferences:com.apple.preference.security?Privacy_Diagnostics
Privacy-Calendars x-apple.systempreferences:com.apple.preference.security?Privacy_Calendars
Privacy-Reminders x-apple.systempreferences:com.apple.preference.security?Privacy_Reminders
Privacy-Facebook x-apple.systempreferences:com.apple.preference.security?Privacy_Facebook
Privacy-LinkedIn x-apple.systempreferences:com.apple.preference.security?Privacy_LinkedIn
Privacy-Twitter x-apple.systempreferences:com.apple.preference.security?Privacy_Twitter
Privacy-Weibo x-apple.systempreferences:com.apple.preference.security?Privacy_Weibo
Privacy-Tencent Weibo x-apple.systempreferences:com.apple.preference.security?Privacy_TencentWeibo
Dictation & Speech Preference Pane
Dictation x-apple.systempreferences:com.apple.preference.speech?Dictation
Text to Speech x-apple.systempreferences:com.apple.preference.speech?TTS
Sharing Preference Pane
Main x-apple.systempreferences:com.apple.preferences.sharing
Screen Sharing x-apple.systempreferences:com.apple.preferences.sharing?Services_ScreenSharing
File Sharing x-apple.systempreferences:com.apple.preferences.sharing?Services_PersonalFileSharing
Printer Sharing x-apple.systempreferences:com.apple.preferences.sharing?Services_PrinterSharing
Remote Login x-apple.systempreferences:com.apple.preferences.sharing?Services_RemoteLogin
Remote Management x-apple.systempreferences:com.apple.preferences.sharing?Services_ARDService
Remote Apple Events x-apple.systempreferences:com.apple.preferences.sharing?Services_RemoteAppleEvent
Internet Sharing x-apple.systempreferences:com.apple.preferences.sharing?Internet
Bluetooth Sharing x-apple.systempreferences:com.apple.preferences.sharing?Services_BluetoothSharing
- 1. Tùy chọn ứng dụng ca cao XCode?
- 2. Nút Ca cao sẽ sáng lên bằng chuột trên
- 3. Cách lấy ngôn ngữ hệ thống và ngôn ngữ hệ thống trong ca cao
- 4. Làm cách nào để hệ thống chọn đúng Bảng Trang?
- 5. Trong ca cao, tôi có phải thực hiện mở rộng quy mô của riêng mình trong drawRect không: nếu tôi chọn phân trang tùy chỉnh trong khi in?
- 6. Cách mở hộp thoại "Tùy chọn hiệu suất" từ dòng lệnh hoặc gọi hệ thống
- 7. PHP: Tạo hệ thống CMS mở rộng
- 8. Ca cao NSStatusBar Global HotKey
- 9. Chế độ xem tùy chỉnh ca cao cho NSMenuItem
- 10. cách xử lý nút đóng cửa sổ trong ca cao
- 11. Các tham số kiểu không thuộc hệ thống tùy chọn
- 12. Làm thế nào để thêm bộ chọn/mở tập tin trong ca cao bằng Trình tạo giao diện?
- 13. Ví dụ về thông báo tùy chỉnh ca cao
- 14. ca cao phát mp3
- 15. Query trên Chọn hệ thống Gọi
- 16. Ca cao: Nhấn chuột phải vào NSStatusItem
- 17. Khoảng cách dòng NSTextField Ca cao
- 18. Ca cao chuyển tiêu điểm sang ứng dụng của tôi
- 19. Kích hoạt trong một hệ thống giao dịch cao
- 20. Lựa chọn ngôn ngữ lập trình cho các hệ thống toàn vẹn cao
- 21. Ca cao không có XCode
- 22. Hệ thống giới thiệu trang web
- 23. Hệ thống chuyên gia nguồn mở
- 24. Hệ thống huy hiệu trang web
- 25. Có bao nhiêu tài nguyên hệ thống sẽ được tổ chức để giữ 1.000.000 websocket mở?
- 26. Có nhiều video Ca cao và Ca cao cảm ứng có giá trị hơn không?
- 27. Làm cách nào để triển khai danh sách tùy chỉnh trong Ca cao?
- 28. Tùy chọn tốt nhất để xây dựng hệ thống plugin cho ứng dụng Moose là gì?
- 29. Thay đổi Tùy chọn Hệ thống Âm thanh (hoặc khác) trong Mac OS X
- 30. Logger tốt nhất cho ca cao
Đây là thực sự mát mẻ, cảm ơn bạn. – Raffael
Tôi đã gõ lệnh 'sdef' trong thiết bị đầu cuối, nhận được lỗi và cảnh báo sau:' sdp: error: class "pane" kế thừa từ lớp không xác định "mục". sdp: lỗi: lớp "neo" kế thừa từ lớp không xác định "mục" .' Vì vậy, tôi không thể lấy tệp tiêu đề. – Gon
@Gon: phiên bản OS X nào? Tôi sẽ xem xét điều này khi tôi có cơ hội ... – NSGod