0

我正在尝试制作一个applescript来将一些文件备份到Dropbox。我的问题是是否可以在我的脚本中组合多个 IF statmen,以及是否可以缩短 SET name TO 路径,例如 Macintosh HD:Users:svkrzn:Dropbox to ~:Dropbox。

这是我的脚本:

set destination to "Macintosh HD:Users:svkrzn:Dropbox:Backup"
set safari to "Macintosh HD:Users:svkrzn:Library:Safari:Bookmarks.plist"
set safariplist to "Macintosh HD:Users:svkrzn:Dropbox:Backup:Safari_Bookmarks.plist"
set things to "Macintosh HD:Users:svkrzn:Library:Application Support:Cultured Code:Things:Database.xml"
set thingsxml to "Macintosh HD:Users:svkrzn:Dropbox:Backup:THINGS_Database.xml"

tell application "Finder"
    try
    set S1 to duplicate file safari to folder destination with replacing
    set T1 to duplicate file things to folder destination with replacing
    if exists file safariplist then
        display dialog "It exists."
        delete file safariplist
    end if
    if exists file thingsxml then
        display dialog "It exists."
        delete file thingsxml
    end if
    set name of S1 to "Safari_Bookmarks.plist"
    set name of T1 to "THINGS_Database.xml"
 on error
    display dialog "Oops, a problem occurred duplicating the file."
 end try
end tell
4

1 回答 1

0

如果语句可以是这样的......

if something then
    -- do something
else if somethingElse then
    -- do something else
else if anotherThing then
    -- do the other thing
else
    -- if none of the others are true then do this
end if

在 applescript 中,我们使用“path to”命令来访问标准文件夹。Applescript 知道很多标准文件夹。打开 AppleScript 编辑器,在“窗口”菜单下选择“库”。找到“Standard Additions”应用程序并双击它以打开 Applescript 的 Standard Additions 字典。搜索“path to”并查看 Applescript 知道的所有标准文件夹。

例如,您可以这样做...

set destination to (path to home folder as text) & "Dropbox:Backup"
于 2012-08-05T12:48:57.007 回答