Applescript 设置脚本尝试装入网络驱动器时的过期时间

Applescript 设置脚本尝试装入网络驱动器时的过期时间,applescript,Applescript,下面的启动脚本在我的macbook中安装网络驱动器: try tell application "Finder" mount volume "afp://iMac-01._afpovertcp._tcp.local/Backup%20HD" end tell end try 对于我来说,此脚本存在两个问题: 如果我不在网络驱动器所在的本地网络中,脚本将花费很长时间尝试与它连接,并使我的macbook在初始化时变得缓慢。那么,如何设置脚本尝试连接网络驱动器的最长时间 如果网络

下面的启动脚本在我的macbook中安装网络驱动器:

try
  tell application "Finder"
     mount volume "afp://iMac-01._afpovertcp._tcp.local/Backup%20HD"
  end tell
end try
对于我来说,此脚本存在两个问题:

  • 如果我不在网络驱动器所在的本地网络中,脚本将花费很长时间尝试与它连接,并使我的macbook在初始化时变得缓慢。那么,如何设置脚本尝试连接网络驱动器的最长时间

  • 如果网络驱动器无法连接,则会弹出一条警告消息。如何忽略此消息?i、 不要让它出现

在此之前,我从未制作过apple脚本,因此,如果可能,请帮助我修改原始脚本

提前谢谢

与timout一起使用'

try
    with timeout of x seconds
        tell application "Finder"
            mount volume "afp://iMac-01._afpovertcp._tcp.local/Backup%20HD"
        end tell
    end timeout
end try
回答您的问题: 1:与mcgrailm状态的超时一起使用;然而,试着只写

with timeout of 2 second --no plural
    <your code here>
end timeout
超时时间为2秒--无复数
结束超时
2:弹出的对话框是一个finder弹出窗口,因此您的脚本无法看到,因为错误永远不会返回到脚本,所以“尝试错误”永远不会被调用,因此如果您想自动单击ok,那么此代码将起作用。此代码将在超时秒后单击按钮

try
    <your code here>
on error
    tell application "System Events"
        keystroke return
    end tell
end try 
试试看
论错误
告诉应用程序“系统事件”
击键返回
结束语
结束尝试
我还包括了我在家里使用的相同想法的版本。这个脚本检查网络,然后尝试使用shell挂载来挂载卷。我最初使用带超时的查找器“mount volume”,代码也作为内联注释存在,但我不喜欢在出现错误时弹出对话框;即使只有一秒钟,所以我继续使用shell脚本

--------------------------------------------------------------------------------------
--"Basic Drive Mounter.app"
try
    set IP_address to "xxx.xxx.xxx.xxx"

    set IP_Valid to true

    try
        do shell script ("ping -c 2 " & IP_address)
    on error
        set IP_Valid to false
    end try

    if IP_Valid then
        tell application "Finder"
            if disk "work" exists then
            else

                try
                    do shell script "mkdir /Volumes/work"
                end try

                do shell script "mount_afp afp://xxx.xxx.xxx.xxx/work /Volumes/work/"

                -->>finder mount volume version
                --with timeout of 2 second
                --  mount volume "afp://xxx.xxx.xxx.xxx/work"
                --end timeout
                --<<finder mount volume version
            end if
        end tell
    end if
on error
    return 0

    -->>finder mount volume version
    --on error finder returns an error dialog which needs to be closed to go back and  retry
    --tell application "System Events"
    --  keystroke return
    --end tell
    --<<finder mount volume version
end try    
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
--“基本驱动器安装程序。应用程序”
尝试
将IP_地址设置为“xxx.xxx.xxx.xxx”
将IP_Valid设置为true
尝试
执行shell脚本(“ping-c2”和IP_地址)
论错误
将IP_Valid设置为false
结束尝试
如果IP_有效,则
告诉应用程序“查找器”
如果存在磁盘“工作”,则
其他的
尝试
执行shell脚本“mkdir/Volumes/work”
结束尝试
执行shell脚本“mount_afp”afp://xxx.xxx.xxx.xxx/work /卷/工作/”
-->>查找器装载卷版本
--超时时间为2秒
--“装入卷”afp://xxx.xxx.xxx.xxx/work"
--结束超时
--查找器装载卷版本
--on error finder返回一个错误对话框,需要关闭该对话框才能返回并重试
--告诉应用程序“系统事件”
--击键返回
--结束语

--该脚本忽略超时,并花费大约2分钟发送警告。和以前一样(你接受了我的答案,那么这对你有用吗?还是你必须修改我的代码?