2013-10-01 119 views
0

此脚本将WAV文件重命名为AIF,并在每个文件的末尾添加2秒的静音,然后删除WAV文件并将所有内容移动到根目录并删除空文件夹。在Applescript中执行Shell脚本问题

问题是通过Applescripts“do shell script”行不执行。

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

如果我将它作为“do script”运行,那很好。

脚本:

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 

理想的情况下这将是巨大的,如果这一切通过跑 “做shell脚本。” 另外任何想法如何当重命名为.aif时我可以放弃.wav?这些文件是这样出来的; newfile.wav.aif

回答

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"/*/ 
+0

感谢您正确的地方,我需要确定SOX。绝对会考虑shell脚本。 – davidt