Applescript将文档中的行保存为变量

时间:2015-06-15 15:31:45

标签: applescript automator

如果我的文字文件如下:

Hi my name is John
How are you doing?

如何让Applescript(和/或Automator)将声音文件保存在桌面上? translate.google.com/translate_tts?tl=en&q=LINE_GOES_HERE

对于上面的示例文本文件,我需要两个声音文件:

来自http://translate.google.com/translate_tts?tl=en&q="Hi my name is John"

的一个

http://translate.google.com/translate_tts?tl=en&q="How are you doing?"

中的一个

也许脚本也可以重命名文件,所以第一个被称为" 001"第二个" 002"?

1 个答案:

答案 0 :(得分:0)

很容易回答下载步骤:

on run
    try
        -- choose the text file
        set text_file to choose file with prompt "Select your text file"
    on error
        return
    end try
    -- read all lines of the text file
    set all_lines to paragraphs of (read text_file as «class utf8»)
    -- reset the addon counter
    set line_count to 0
    -- walk through the lines
    repeat with a_line in all_lines
        -- handle only lines with content
        if a_line ≠ "" then
            -- count the line
            set line_count to line_count + 1
            -- create an addon for later target file
            set add_on to "_" & text -3 thru -1 of ("000" & line_count)
            -- build the URL to load the sound file from
            set url_to_load to "http://translate.google.com/translate_tts?tl=en&q=\"" & a_line & "\""
            -- for this moment log the output only
            -- here you have to put the download code
            log add_on
            log url_to_load
        end if
    end repeat
end run

但正如我在评论中所提到的,你必须找到一种自动下载声音文件的方法!

但也许第一种方法有帮助!迈克尔/汉堡