Answers:
您可以编辑存储设置的属性列表并重新打开DictationIM进程:
#!/bin/bash
k="com.apple.speech.recognition.AppleSpeechRecognition.prefs DictationIMLocaleIdentifier"
if [[ "$(defaults read $k)" == en-US ]]; then
defaults write $k fr-FR
defaults write com.apple.assistant "Session Language" fr-FR
else
defaults write $k en-US
defaults write com.apple.assistant "Session Language" en-US
fi
killall -HUP DictationIM
或者使用UI脚本:
tell application "System Preferences"
reveal anchor "Dictation" of pane "com.apple.preference.speech"
end tell
tell application "System Events" to tell process "System Preferences"
tell pop up button 1 of tab group 1 of window 1
click
if value is "English (United States)" then
click menu item "French" of menu 1
else
click menu item "English (United States)" of menu 1
end if
end tell
end tell
quit application "System Preferences"
这两个脚本都是从我的答案复制而来的 如何使用applescript切换新听写工具的语言设置(10.8) - Stack Overflow 。
-eq
不适用于字符串IIRC。
activate
来自AppleScript。
不确定这是否有帮助,但有人开发了一个“听写切换器”一个小实用程序,位于Mac的菜单栏中,使得使用听写更容易。在这里能找到它: http://fouquet.me/apps/dictationswitcher/
明白你有幸编写自己的脚本,但为了以防万一,我认为这可能会有所帮助... :-)
我发现了一个 线 其中包含以下Applescript:
tell application "System Events" to set p to (path to frontmost application) as string
tell application "System Preferences"
activate
reveal anchor "Dictation" of pane "com.apple.preference.speech"
end tell
tell application "System Events"
tell process "System Preferences"
tell pop up button 1 of tab group 1 of window "Dictation & Speech"
click
if (get value of attribute "AXValue") contains "English (United States)" then
click menu item "German" of menu 1
say "Dictation set to German"
else if (get value of attribute "AXValue") contains "German" then
click menu item "English (United States)" of menu 1
say "Dictation set to English"
end if
end tell
end tell
end tell
quit application "System Preferences"
activate application p
我测试了它,它的工作原理。您所要做的就是将“德语”更改为您选择的语言。
另外,我可以建议一个名为的应用程序 FastScripts ,允许您从顶部菜单栏或键盘快捷键运行applescript。
希望这能解决你的问题!
activate
,它也会工作,而不是显示窗口。
检查一下 http://fouquet.me/apps/dictationswitcher/ 是非常好的。 我希望这有帮助
在OSX El Capitan上,我很难通过user495470获取脚本,同样使用pasawaya的代码。我最终修改了pasawaya的代码,包括:
repeat until exists tab group 1 of window "Dictation & Speech"
end repeat
这是完全略微修改的脚本,对我来说非常适合:
tell application "System Events" to set currentWindow to (path to frontmost application) as string
tell application "System Preferences"
reveal anchor "Dictation" of pane "com.apple.preference.speech"
end tell
tell application "System Events"
tell process "System Preferences"
repeat until exists tab group 1 of window "Dictation & Speech"
end repeat
tell pop up button 1 of tab group 1 of window "Dictation & Speech"
click
if (get value of attribute "AXValue") contains "English" then
click menu item "Danish (Denmark)" of menu 1
say "Dictation Danish"
else if (get value of attribute "AXValue") contains "Danish" then
click menu item "English (United Kingdom)" of menu 1
say "Dictation English"
end if
end tell
end tell
end tell
quit application "System Preferences"
activate application currentWindow