如何使用AppleScript下载新的语音功能?

时间:2014-03-20 21:30:11

标签: applescript

我正在寻找一种方法来在系统首选项上安装不同的声音(准确地说是2)。 声音是英语声音的“Alex”和法语声音的“Thomas”。

我直接尝试使用控制台,但没有成功,这就是为什么我转向AppleScript语言,但我从未使用过这种语言。

我目前的代码是

set osver to system version of (system info)
if osver is equal to "10.6.8" then
    display dialog ("Downloading voices is only available in OS X Lion and higher")
else
    tell application "System Preferences"
        activate
        reveal (pane id "com.apple.preference.speech")
    end tell

    try
        tell application "System Events"
            click radio button 2 of tab group 1 of window 1 of process "System Preferences"
            repeat until (exists pop up button of tab group 1 of window 1 of process "System Preferences")
                delay 2
            end repeat
            delay 2
            click pop up button 1 of tab group 1 of window 1 of process "System Preferences"
            delay 2
            click menu item -1 of menu 1 of pop up button of tab group 1 of window 1 of process "System Preferences"
            delay 2
        end tell
    on error
        display dialog ("An error happend")
    end try
end if

此程序正在打开语音窗口,但每次出现索引时都会出现显示对话框。

如果您有其他想法下载声音,或者如果您可以帮助我了解哪些不起作用,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

这在10.9中对我有用:

tell application "System Preferences"
    reveal anchor "TTS" of pane id "com.apple.preference.speech"
    activate
end tell
tell application "System Events" to tell window 1 of process "System Preferences"
    tell pop up button 1 of tab group 1
        click
        click menu item "Customize..." of menu 1
    end tell
    delay 1
    repeat with r in UI element 1 of rows of table 1 of scroll area 1 of sheet 1
        if exists static text 1 of r then
            if {"Alex", "Thomas"} contains value of static text 1 of r then
                if value of checkbox 1 of r is 0 then click checkbox 1 of r
            end if
        end if
    end repeat
    click button "OK" of sheet 1
end tell

虽然运行脚本需要几秒钟。