0

我越来越多地使用launchd来自动化我的家庭服务器上的一切,我想在我的客户端机器上利用它的一些力量。我基本上想弄清楚如何始终保持服务器的 AFP 共享。我看到自己遇到的唯一真正的问题是,当我在 AFP 被阻止的网络上时,脚本会将自己撞到墙上。我想做一些尝试3次然后放弃的事情,但是当我离开网络时我必须重新启动脚本。我不太确定如何在 plist 中编写 if 构造以确保它可以连接,或者检查卷是否已安装。到目前为止,我编写的唯一脚本是让 OS X 应用程序保持活力。

4

1 回答 1

0

看看LocationChanter。它使用的 plist 项是:

<key>WatchPaths</key>
<array>
    <string>/Library/Preferences/SystemConfiguration</string>
</array>

据我所知,每次网络更改时,该目录中的文件都会更新。所以这会给你你的第一个触发器。另一个要查看的 plist 项目是“PathState”。launchd.plist 手册页包含以下文档:

PathState <dictionary of booleans>
Each key in this dictionary is a file-system path. If the value of
the key is true, then the job will be kept alive as long as the
path exists.  If false, the job will be kept alive in the inverse
condition. The intent of this feature is that two or more jobs may
create semaphores in the file-system namespace.

我自己刚刚开始启动,但我认为您可以将其与 WatchPaths 结合使用来设置您正在寻找的内容。想法是监视已安装的驱动器,如果不存在则尝试安装它。

当然,您可能需要对此进行一些限制。特别是如果客户端机器将连接到其他网络,但我认为这些元素应该让你开始。

于 2011-08-11T03:39:21.043 回答