1

我是 Applescript 的新手,正在尝试整理一个简单的脚本来在运行时备份一些文件夹。我的脚本如下:

on run
    tell application "Finder"
        set backupFolder to make new folder at "BACKUP" with properties {name:(year of (current date) as string) & "-" & (month of (current date) as integer as string) & "-" & (day of (current date) as string)}
        duplicate folder "~/Test" to backupFolder
    end tell
end run

但是,当我运行脚本时,我收到一条错误消息:

Finder got an error: Can’t set folder "2013-1-9" of disk "BACKUP" to folder "~/Test".

这似乎是一个微不足道的问题,但我不知道如何解决它。谁能让我知道我做错了什么?

4

2 回答 2

1

用以下内容替换您的重复...行:

duplicate folder POSIX file "~/Test" to backupFolder
于 2013-01-09T11:59:37.637 回答
1

AppleScript大部分时间都不理解"~/Test"(甚至不理解)。"/Users/username/Test/"

set d to (year of (current date) as text) & "-" & (month of (current date) as integer as text) & "-" & (day of (current date) as text)
tell application "Finder"
    set f to make new folder at POSIX file "/Users/username/Backups/" with properties {name:d}
    duplicate POSIX file "/Users/username/Test/" to f
end tell

/Users/username可以替换为system attribute "HOME"。您也可以"Macintosh HD:Users:username:Test"直接使用 HFS 路径(如 )。

不过,使用 shell 脚本会更容易:

d=~/Backup/$(date +%Y-%m-%d)/
mkdir -p $d
cp -R ~/Test $d
于 2013-01-09T11:59:52.383 回答