문제

I'm trying to make a very simple applescript, but I've encountered a problem and can't move forward from here.

What my program should do is very simple. It reads a text file, splits it's content to generate an array and then does a shell script to leverage mac terminal's say command to read and save the text into a .wav file.

On the terminal I can save a file in wav format using this: say -o "hello.wav" --data-format=LEF32@32000 "hello world"

I tried to mimic that code in my applescript to no avail, here is the code:

set theFile to (choose file with prompt "Select a file to read:" of type {"TXT"})
open for access theFile
set fileContents to (read theFile)
close access theFile

set everyLine to every paragraph of fileContents

repeat with theLine in everyLine
    set thisOne to split(theLine, ";")
    set fileName to item 1 of thisOne

    do shell script "say -o" & item 1 of thisOne & ".wav --data-format=LEF32@32000 " & item 3 of thisOne

end repeat

to split(someText, delimiter)
    set AppleScript's text item delimiters to delimiter
    set someText to someText's text items
    set AppleScript's text item delimiters to {""} --> restore delimiters to default value
    return someText
end split

Running this code results in Opening output file failed: -43.

Even a simple do shell script "say -o hello.aiff hello returns the same error. I would greatly appreciate any help, including telling me I simply can't do this and I should learn a proper programming language :)

도움이 되었습니까?

해결책

The script doesn't have the permissions to save files at the root directory. You can either run the script with administrator privileges or save the file to another location, like your home directory.

do shell script "say -o $HOME/hello.aiff hello"

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top