首页 > 解决方案 > 使用用户生成的名称复制当前路径的文件夹(applescript)

问题描述

我正在尝试设置一个applescript

  1. 要求用户输入文本
  2. 使用输入数据创建一个新文件夹
  3. 将文件从另一个文件夹复制到此文件夹

这是我到目前为止所拥有的,但我收到错误消息:“找不到文件 /Users/*****/Desktop/Temp/_scripts/”

tell application "Finder"
    set newfoldername to text returned of (display dialog "Project name:" default answer "no name")
    set loc to container of (path to me) as alias

    set newclient to make new folder at loc with properties {name:newfoldername}
    set structure to ((POSIX path of loc) & "_scripts/") as alias

    duplicate folder structure to loc

end tell

_scripts 文件夹与我的 applescript 位于同一文件夹中。它是否需要一个文件而不是一个文件夹?

标签: applescript

解决方案


最严重的错误是 Finder 无法识别 POSIX 路径。

如果要将"_scripts"与运行脚本处于同一级别的文件夹复制到新创建的文件夹,只需使用 Finder 说明符语法 ( folder "_scripts" of loc)

tell application "Finder"
    set newfoldername to text returned of (display dialog "Project name:" default answer "no name")
    set loc to container of (path to me)

    set newclient to make new folder at loc with properties {name:newfoldername}
    duplicate folder "_scripts" of loc to newclient

end tell

推荐阅读