如何使用Applescript创建文件夹(包含子文件夹)

时间:2012-11-02 02:43:10

标签: macos applescript finder

Filemaker能够使用AppleScript。

从Filemaker中我想创建一个包含6个子文件夹的新文件夹(名称为FileMaker字段)。

对于Applescript来说,我是一个完整的菜鸟。

到目前为止,这是我的脚本:

tell application "FileMaker Pro Advanced"
set folder_name to cell "FolderName" of current record
end tell
tell application "Finder"
     activate
     make new folder at folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:folder_name}
end tell
tell application "Finder"
     activate
        make new folder at folder {name:folder_name} of folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:"subfolder"}
end tell

我的问题是:创建“Subfolder1”

我的错误是什么?

非常感谢帮助

2 个答案:

答案 0 :(得分:2)

当您创建新文件夹时,您可以定义各种属性,但在引用该文件夹时只需使用该名称,例如:

make new folder at folder folder_name of folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:"subfolder"}

请注意,制作新文件夹时返回的结果是对该文件夹的引用,因此您还可以执行以下操作:

tell application "Finder"

  set newFolder to (make new folder at folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:folder_name})

  make new folder at newFolder with properties {name:"subfolder"}

end tell

答案 1 :(得分:2)

这是另一种方法:

set myPath to POSIX path of ((path to desktop as text) & folder_name & ":subfolder")
do shell script "mkdir -p " & myPath