0

我有一个脚本,我需要在使用该脚本创建文件夹的位置(如下)编写,但由于其命名方式,无法弄清楚如何将文件复制到创建的文件夹中。

set foo to computer name of (system info)
tell application "Finder"
    set home_path to home as Unicode text
    set targetFile to (home_path & "Library:Logs:Xxxxx.log")
    set p to (path to desktop)
    try
    set targetPath to make new folder at p with properties **{name:"XXX-X-XXXX" & foo}**
        duplicate file targetFile to targetPath
    end try
end tell

我想我可以写一个这样的脚本。

set foo to computer name of (system info)


    tell application "Finder"
        set p to (path to desktop)

        set home_path to home as Unicode text
        set targetFile to (home_path & "Library:Logs:Xxxxx.log")
        set p to (path to desktop)
        try
            set targetPath to p & {name:"LOGS-I-NEED" & foo}
            duplicate file targetFile to targetPath
        end try
        try
        on error the error_message number the error_number
            display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
        end try

    end tell

但我得到这个错误

--> 错误编号 -1700 从 {alias "Macintosh HD:Users:dorianglanville:Desktop:", "LOGS-I-NEEDDorian's MacBook"} 到文件夹

我觉得我错过了一些简单的东西,但一直盯着它看太久了,我不再“看到”它。

多谢你们!

4

1 回答 1

1

尽管您需要纠正一些事情,但该错误与撇号无关。

error number -1700 from {alias "Macintosh HD:Users:dorianglanville:Desktop:", "LOGS-I-NEEDDorian's MacBook"} to folder

请注意,targetPath 由两项组成。您需要将其强制为文本。

set foo to computer name of (system info)
set p to (path to desktop)
set targetFile to (path to library folder from user domain as text) & "Logs:Xxxxx.log"
set targetPath to p & "LOGS-I-NEED" & foo as text

try
    tell application "Finder" to duplicate file targetFile to targetPath
on error the error_message number the error_number
    display dialog "Error: " & the error_number & ". " & the error_message & return & "targetFile:" & targetFile & return & return & "targetPath:" & targetPath buttons {"OK"} default button 1
end try 
于 2013-05-04T11:04:10.380 回答