2012-08-04 26 views
0

我想讓一個applescript將一些文件備份到dropbox。我的問題是,如果可以在我的腳本中合併多個IF statmens,並且可以縮短SET名稱TO路徑,如Macintosh HD:用戶:svkrzn:Dropbox to〜:Dropbox。Applescript-結合多個IF語句和家庭文件夾的縮寫

這裏是我的腳本:

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 

回答

0

IF語句可以像這樣...

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的,我們使用 「路徑」 命令來獲得標準的文件夾。 Applescript知道很多標準文件夾。打開AppleScript編輯器,在「窗口」菜單下選擇「庫」。找到「Standard Additions」應用程序並雙擊它打開Applescript的Standard Additions字典。搜索「路徑」並查看Applescript知道的所有標準文件夾。

例如,你可以做到這一點...

set destination to (path to home folder as text) & "Dropbox:Backup"