Terminal 带终端的Applescript查找和删除文件夹

Terminal 带终端的Applescript查找和删除文件夹,terminal,applescript,Terminal,Applescript,因此,我想尝试制作一个脚本,用applescript查找并删除文件夹中的多个文件夹: tell application "Terminal" activate do script "find (Path to folder) -type d *-name "Foldername*" -exec rm -rf {} \;*" end tell Applescript不会在类型d之后运行任何东西,因为“Syntaxerror expected end of row”,但我不明白为

因此,我想尝试制作一个脚本,用applescript查找并删除文件夹中的多个文件夹:

tell application "Terminal"
    activate
    do script "find (Path to folder) -type d *-name "Foldername*" -exec rm -rf {} \;*"

end tell
Applescript不会在类型d之后运行任何东西,因为“Syntaxerror expected end of row”,但我不明白为什么,因为如果我运行

find (Path to folder) -type d *-name "Foldername*" -exec rm -rf {} \;* 

在终端

中,您可以使用命令
do shell script
,该命令的作用与在终端中运行它相同。您不需要
tell
块来运行此操作

这里还有两点需要在脚本中查看

  • 如果要在已引用的shell脚本中使用
    引号,则需要使用
    \
    对其进行转义。 i、 e.
    “一些脚本\”一些名字\“更多脚本”
    。 否则,只需在双引号脚本中使用单引号

  • 如果希望脚本中的
    \
    run,则需要在Applescript中转义它。 i、 e.
    rm-rf{}\\\;*“

  • 最终脚本看起来更像这样:

    do shell script "find (Path to folder) -type d *-name 'Foldername*' -exec rm -rf {} \\;*"
    

    您为什么不使用
    do shell脚本
    命令?