Applescript包文件夹

时间:2014-05-12 21:47:52

标签: applescript

我试图将文件夹移动到包文件夹(扩展名为.tblk的文件夹)。

代码:

tell application "Finder"

    set theFolder to (choose folder with prompt "Choose source folder" default location (path to downloads folder))

    set theResources to make new folder at theFolder with properties {name:"Resources"}

    set theContents to make new folder at theFolder with properties {name:"Contents"}

    move theResources to theContents

    set thePackage to make new folder at theFolder with properties {name:"package.tblk"}

    move theContents to thePackage -- error here

    set theConfigurations to (choose folder with prompt "Choose destination folder" default location (path to desktop folder))

    move thePackage to theConfigurations

end tell

错误:

  

Finder收到错误:无法生成文档文件" Package.tblk"的文件夹   "桌面"文件夹" craibuc"文件夹"用户"启动盘进入   类型文件夹。

如果这一行:

set thePackage to make new folder at theFolder with properties {name:"package.tblk"}

更改为:

set thePackage to make new folder at theFolder with properties {name:"package"}

然后脚本按预期工作。

有没有更好的方法来处理这些类型的文件夹?

1 个答案:

答案 0 :(得分:1)

在完成其他工作后,重构代码以创建包。在文件夹扩展名更改后使用别名来保留文件引用:

tell application "Finder"

  set theFolder to (choose folder with prompt "Choose source folder" default location (path to downloads folder))

  set theResources to make new folder at theFolder with properties {name:"Resources"}

  set theContents to make new folder at theFolder with properties {name:"Contents"}
  move theResources to theContents

  set thePackage to make new folder at theFolder with properties {name:"Package"}
  move theContents to thePackage

  set thePackageAlias to thePackage as alias
  set the name extension of thePackageAlias to "tblk"

  set theConfigurations to (choose folder with prompt "Choose destination folder" default location (path to desktop folder))

  move thePackageAlias to theConfigurations

end tell