【问题标题】:applescript + shell script problemapplescript + shell 脚本问题
【发布时间】:2010-12-12 21:45:07
【问题描述】:

我正在编写一个脚本来跟踪渲染中丢失的帧(数千个图像文件)。要找到序列中编号的帧,我这样做:

set thecontents to every paragraph of (do shell script
"while IFS= read -r -d '' file;
do echo \"$file\"|sed -E \"s|.*[^[:digit:]]0*([[:digit:]]+)\\..*|\\1|\" ;
done< <(find \"" & thefolderPPath & "\" -name \"*.*\" -print0)")

find 找到所有文件,然后 sed 将除尾随数字之外的所有文件都去掉 - 当文件编号为 foo_001.bar(或者即使它们是 foo3_001.bar)时,它会匹配数字,它会查找非数字, 后跟一系列数字,后跟一个点扩展名,然后删除除数字之外的所有内容。

如果我像这样运行它(没有转义),它可以在 shell 中运行

while IFS= read -r -d '' file
do echo "$file"|sed -E "s:.*[^[:digit:]]0*([[:digit:]]+)\..*:\1:" 
done < <(find "/Volumes/foo/imagesequence/" -name "*.*" -print0)

它产生了一个很好的数字列表,但在 Applescript 我得到了

"sh: -c: line 0: 附近有语法错误 意外令牌`

有什么想法吗?我可以通过将 sed 函数和 find 函数分解为单独的 shell 脚本来使用 applescript 来实现它,但这会慢一些。

【问题讨论】:

    标签: macos shell find applescript


    【解决方案1】:

    您似乎在这里使用bash 进程替换:

    <(find "/Volumes/foo/imagesequence/" -name "*.*" -print0)
    

    AppleScript do shell script 命令始终使用/bin/shPosix shell 语义),Posix /bin/sh 不支持进程替换。重写脚本以避免Bash-isms 或遵循here 的建议,了解如何使用另一个shell 运行AppleScript shell 脚本。

    【讨论】:

    • 好吧,谁知道呢?谢谢。