设置脚本尝试挂载网络驱动器时的过期时间
下面的启动脚本在我的 macbook 中安装网络驱动器:
try
tell application "Finder"
mount volume "afp://iMac-01._afpovertcp._tcp.local/Backup%20HD"
end tell
end try
对于我来说,此脚本有两个问题:
如果我不在网络驱动器所在的本地网络中,则脚本需要很长时间才能尝试连接有了它,并使我的 MacBook 初始化缓慢。那么,如何设置脚本尝试连接网络驱动器的最长时间?
如果无法连接网络驱动器,则会弹出一条警告消息。如何忽略此消息?即,让它不出现。
我之前从未制作过苹果脚本,所以如果可能的话,请帮助我修改原始脚本。
提前致谢。
The start up script bellow mounts a network drive in my macbook:
try
tell application "Finder"
mount volume "afp://iMac-01._afpovertcp._tcp.local/Backup%20HD"
end tell
end try
There is two problems with this script for me:
If I am out of the local network that the network drive is located, the script takes a long time trying to connect with it, and makes my macbook slowly in initialization. So, how to setup a maximum time for the script try to connect with the network drive?
If the network drive cannot be connected, a message warning me of that pops out. How to ignore this message? i.e, make it not appears.
I'm never made an apple script before of that, so please, if it is possible, help me modifying the original script.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用“带超时”
use 'with timout'
回答你的问题:
1:按照 mcgrailm 的规定使用超时;但是尝试只写
2:弹出的对话框是一个查找器弹出窗口,因此您的脚本看不到它,“尝试错误”永远不会被调用,因为错误永远不会返回到脚本,所以如果您想自动化单击“确定”,然后此代码将起作用。此代码将在超时秒数后单击按钮。
我还包含了我在家使用的相同想法的版本,此脚本会检查网络,然后尝试使用 shell 安装来安装卷。我最初使用带有超时功能的查找器“安装卷”,并且代码也作为内联注释存在,但我不喜欢在错误时弹出对话框;即使只有一秒钟,所以我转向 shell 脚本。
to answer your questions:
1: use with timeout as mcgrailm states; however try just writing
2: the dialog that pops up is a finder popup and as such your script cannot see that, the "try on error" never gets called as the error is never returned to the script, so if you want to automate the click on ok then this code will work. This code will click the button after your timeout seconds.
i have also included my version of the same idea which i use at home this script does a check of the network, then tries to mount the volume using a shell mount. i originally used a finder "mount volume" with timeout and that codes exists as inline comments too, but I didn't like the dialog popping up on errors; even if only for a second, so i moved on to shell script.