Applescript在出错时不退出

时间:2016-11-21 16:58:47

标签: applescript rsync

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

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

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

1 个答案:

答案 0 :(得分:0)

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

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

      ...

    end try
end repeat