使用用户生成的名称(applescript)在当前路径复制文件夹

使用用户生成的名称(applescript)在当前路径复制文件夹,applescript,Applescript,我正试图建立一个苹果脚本 要求用户输入文本 使用输入数据创建一个新文件夹 将文件从其他文件夹复制到此文件夹 这是我到目前为止所知道的,但我得到了一个错误:“文件/用户/*******/桌面/临时/_脚本/找不到” _scripts文件夹与我的applescript位于同一文件夹中。它需要的是文件而不是文件夹吗?最严重的错误是查找程序无法识别POSIX路径 如果要将文件夹“\u scripts”复制到新创建的文件夹中,只需使用查找器说明符语法(loc的文件夹”\u scripts) 已经解释了OP

我正试图建立一个苹果脚本

  • 要求用户输入文本
  • 使用输入数据创建一个新文件夹
  • 将文件从其他文件夹复制到此文件夹
  • 这是我到目前为止所知道的,但我得到了一个错误:“文件/用户/*******/桌面/临时/_脚本/找不到”


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

    最严重的错误是查找程序无法识别POSIX路径

    如果要将文件夹
    “\u scripts”
    复制到新创建的文件夹中,只需使用查找器说明符语法(
    loc的文件夹”\u scripts)

    已经解释了OP的代码不能按预期工作的原因,并且已经给出了一个可行的解决方案

    对于可能需要别名以供重用的其他人,我们还可以通过在路径字符串之前显式地说“POSIX file”来转换文件路径格式:

    set structure to POSIX file ((POSIX path of loc) & "_scripts/") as alias
    
    (因为脚本应该复制到
    newclient
    ,所以最后一行也会被修改,)完整代码如下:

    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 file ((POSIX path of loc) & "_scripts/") as alias
    
        duplicate folder structure to newclient
    
    end tell
    

    另外,建议检查
    \u scripts/
    文件夹是否存在,如果无法控制,则检查要创建的文件夹是否不存在。

    谢谢,我没有意识到这一点
    set structure to POSIX file ((POSIX path of loc) & "_scripts/") as alias
    
    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 file ((POSIX path of loc) & "_scripts/") as alias
    
        duplicate folder structure to newclient
    
    end tell