首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误时不要退出Applescript

错误时不要退出Applescript
EN

Stack Overflow用户
提问于 2016-11-21 16:58:47
回答 1查看 44关注 0票数 0

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

代码语言:javascript
复制
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

这是很好的工作,并产生一个日志,它所做的。除非有什么问题。然后它就会退出。我想要改变它,这样它就会忽略错误并继续进行下去。有什么想法吗?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-21 17:12:06

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

代码语言:javascript
复制
repeat with i from 1 to count of Servers
    set thisServer to item i of Servers
    try

      ...

    end try
end repeat
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40725456

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档