Applescript 在出错时不退出

Applescript to not quit when erroring

我有一个 applescript,用于将文件(使用 rsync)从源复制到多个位置:

set Servers to {"afp://service.username:password@MACSERVER1.domain.com/Public/", "afp://service.username:password@MACSERVER2.domain.com/Public/",  "afp://service.username:password@MACSERVER3.domain.com/Public/",  "afp://service.username:password@MACSERVER4.domain.com/Public/",  "afp://service.username:password@MACSERVER5.domain.com/Public/"}
--these are constant so no need to change
set Source to "/Shared Items/Public/DeployStudio/Masters/HFS/Sierra.hfs.dmg"
set Destination to "/Volumes/Public/DeployStudio/Masters/HFS"
--the scripts that goes recursively through the list of servers
repeat with i from 1 to count of Servers
    set thisServer to item i of Servers
    --this will mount each server destination in turn creating a /Volumes/Public folder
    mount volume thisServer
    --these are two rsync scripts which creates logfiles
    do shell script "/usr/bin/rsync -rlptD --log- file=/Users/username/Documents/logs/Sierra-rsync.log " & (quoted form of Source) & " " & (quoted form of Destination)
    --not sure this is needed but added this 5 sec delay to stop ejecting disk errors
    delay 5
    --eject the mounted volume so we don't have multiple Public folders
    tell application "Finder"
        eject disk "Public"
    end tell
end repeat

这很好用,并生成了它所做的日志。除非有问题。然后它就会退出。我想改变它,让它忽略错误并继续前进。有任何想法吗?谢谢

要忽略重复循环中的错误,请将受影响的代码包装在 try 块中

repeat with i from 1 to count of Servers
    set thisServer to item i of Servers
    try

      ...

    end try
end repeat