0

此脚本是将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?文件是这样出来的;新文件.wav.aif

4

1 回答 1

0

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"/*/
于 2013-10-01T16:11:14.330 回答