Applescript saving lines in document as variables

87 views Asked by At

If I have a text-file looking like this:

Hi my name is John
How are you doing?

How can I get Applescript (and/or Automator) to save the sound-file on my desktop? translate.google.com/translate_tts?tl=en&q=LINE_GOES_HERE

For the example text-file above I need two sound files:

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

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

Perhaps the script can also rename the files, so the first is called "001" and the second "002"?

1

There are 1 answers

0
ShooTerKo On

It's easy to answer the steps around the download:

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

But as mentioned in my comment you have to find a way to automatically download the sound file!

But maybe this first approach helps! Michael / Hamburg