Applescript与终端查找和删除文件夹

时间:2014-09-22 16:55:22

标签: terminal applescript

所以我想尝试创建一个脚本来查找和删除带有applescript的文件夹中的多个文件夹:

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

end tell

Applescript不会在 -type d 之后运行任何东西,因为“Syntaxerror期望行结束”但我不明白为什么因为它运行时如果我运行

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

在终端

1 个答案:

答案 0 :(得分:2)

您可以使用命令do shell script,它与在终端中运行它的功能相同。并且您不需要tell块来运行它。

此外,您还可以在脚本中查看两点。

  1. 如果您想在已引用的shell脚本中使用"引号,则需要使用\转义它们。     即"some script \"some name\" some more script"。 否则,只需在双引号脚本中使用单引号。

  2. 如果您希望脚本中的\ 运行,则需要在Applescript中将其转义。     即rm -rf {} \\;*"

  3. 最终脚本看起来更像是这样:

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