Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用AppleScript将文件复制到同一文件夹中的另一个文件_Applescript - Fatal编程技术网

如何使用AppleScript将文件复制到同一文件夹中的另一个文件

如何使用AppleScript将文件复制到同一文件夹中的另一个文件,applescript,Applescript,我有以下AppleScript: to copyMovieTemplate(sermonCode) local iMovieProject set iMovieProject to ((iMovieSermonsPath as text) & sermonCode & ".rcproject") display dialog ("Copying " & (sermonTemplate) & " to " & (iMovieProj

我有以下AppleScript:

to copyMovieTemplate(sermonCode)
    local iMovieProject
    set iMovieProject to ((iMovieSermonsPath as text) & sermonCode & ".rcproject")

    display dialog ("Copying " & (sermonTemplate) & " to " & (iMovieProject as text))

    tell application "Finder"
        duplicate file sermonTemplate to file iMovieProject without replacing
    end tell
end copyMovieTemplate
sermonTemplate
iMovieSermonsPath
变量是
别名

global sermonTemplate
global iMovieSermonsPath

set sermonTemplate to alias ((iMovieSermonsPath as text) & "Sunday Service Template.rcproject")
set iMovieSermonsPath to alias ((iMovieProjects as text) & "Sermons:")
运行此脚本时,我收到一个错误,告诉我Finder无法将目标文件复制到目标文件:

Finder出现错误:无法将文件“Macintosh HD:Users:vitabile:Movies:iMovie Project.localized:Sermons:14-0101-01.rcproject”设置为文件“Macintosh HD:Users:vitabile:Movies:iMovie Project.localized:Sermons:14-0101-01.rcproject”

我做错了什么?做这个拷贝的正确方法是什么

编辑1

我甚至尝试删除
而不替换
子句,但没有任何区别

编辑2

在进一步搜索之后,我找到了,加上评论中的反馈,因此我重写了代码:

-- Copy the Sunday Sermon Template file to the iMove Projects folder
to copyMovieTemplate(sermonCode)
    -- Convert the sermonCode into a file name for the iMovie project
    set iMovieProject to sermonCode & ".rcproject"

    display dialog ("Copying " & (sermonTemplate as text) & " to " & iMovieProject as text)

    tell application "Finder"
        try
            set theCopy to duplicate alias sermonTemplate to folder alias iMovieSermonsPath
            set name of theCopy to iMovieProject
        on error errStr
            display dialog ("Unable to copy the Sunday Sermon Template project to " & (iMovieSermonsPath as text) & iMovieProject & ".")
            display dialog "Error: " & errStr
            error number -128
        end try
    end tell
end copyMovieTemplate
这仍然不起作用,但错误已更改:

Finder出现错误:无法将别名“Macintosh HD:Users:vitabile:Movies:iMovie项目”设置为整数类型


使用系统事件不起作用,因为我遇到了相同的错误。

对于
将iMovieSermonsPath设置为alias(iMovieProjects作为文本)和“Sermons:”
:您犯的错误与您在上一个问题()中犯的错误相同:

代码没有创建单个别名,而是无意中创建了一个列表,该列表的第一个条目是文件夹的别名,其路径是
iMovieProject as text
,其第二个元素是字符串文字“布道”:

要解决此问题,请在将路径字符串传递给
别名之前,将构建路径字符串的整个表达式括起来:

set iMovieSermonsPath to alias ((iMovieProjects as text) & "Sermons:")

我终于发现了我的问题。我为iMovie项目文件夹构建的路径末尾没有冒号。也就是说,我正在构建一条如下所示的路径:

Macintosh HD:用户::电影:iMovie项目。本地化术语:

当它看起来应该是:

Macintosh HD:Users::Movies:iMovie项目。本地化:布道:

一旦我添加了缺失的冒号,它就开始工作了


我还去掉了别名,把所有内容都保留为
text
。我不知道这是否有区别。

请参阅我对OP的第二次编辑。这是一个转录错误。单词
别名
后的整个表达式用括号括起来。我将编辑原始问题以反映事实。我仍然得到问题中提到的错误。@TonyVitabile:明白了。在第二个代码片段中,您正在根据
iMovieSermonsPath
定义
sermonTemplate
,尽管您只是在这之后定义
iMovieSermonsPath