该脚本将WAV文件重命名为AIF,并在每个文件末尾添加2秒的静默,然后删除WAV文件并将所有内容移至根目录并删除空文件夹。

问题是通过Applescripts,“do shell script”行没有执行。

do shell script "find " & rootDirectory & " -name \\*.wav -exec sox {} {}.aif pad 0 2 \\;"

如果我将其作为“执行脚本”运行,那就很好。

脚本:
tell application "Finder" to set rootDirectory to (target of Finder window 1) as string
set rootDirectory to quoted form of POSIX path of rootDirectory

do shell script "find " & rootDirectory & " -name \\*.wav -exec sox {} {}.aif pad 0 2 \\;" -- change to AIF and add 2 second silence
delay 10
do shell script "find " & rootDirectory & " -name \\*.wav -exec rm {} \\;" -- delete WAV files
delay 5
do shell script "find " & rootDirectory & " -type f -exec mv {} " & rootDirectory & " \\;" --Move all files into rootDirectory
do shell script "find " & rootDirectory & " -depth -type d -exec rmdir {} " & " \\;" -- Remove all subdirectories of XMoveTo Root.app:

“执行脚本”解决方法:
tell application "Terminal"
    activate
    do script "find " & rootDirectory & " -name \\*.wav -exec sox {} {}.aif pad 0 2 \\;" in front window
    delay 10
    do script "find " & rootDirectory & " -name \\*.wav -exec rm {} \\;" in front window
end tell

理想的情况是,如果全部都通过“do shell script”运行。
还知道在重命名为.aif时如何松开.wav吗?文件像这样出来; newfile.wav.aif

最佳答案

路径上是否有sox?我无法想到find命令不起作用的任何其他原因。

您可以将脚本编写为Shell脚本:

set -e
dir=$(osascript -e 'tell app "Finder" to POSIX path of (target of Finder window 1 as alias)')
find "$dir" -type f  | while read f; do
  if [[ $f = *.wav ]]; then
    sox "$f" "$dir$(basename "$f" .wav).aif" pad 0 2
    rm "$f"
  else
    mv "$f" "$dir"
  fi
done
rm -r "$dir"/*/

关于shell - 在Applescript中执行Shell脚本问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19118644/

10-12 12:40