How to download a new voice for say's function with AppleScript?

自作多情 提交于 2019-12-25 11:48:12

问题


I'm searching a method to install different voices (2 to be exact) on the system preferences. The voices are "Alex" for an english voice and "Thomas" for a french voice.

I've tried directly by console but didn't succeed, that's why I've turned to the AppleScript language, but I never used this language.

The code I've for the moment is

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

This program is opening the voice window but the display dialog appears every time whatever the index I put.

If you have another idea to download the voices, or if you can help me to understand what is not working, I will be grateful.


回答1:


This worked for me in 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

It took multiple seconds to run the script though.



来源:https://stackoverflow.com/questions/22545517/how-to-download-a-new-voice-for-says-function-with-applescript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!