【问题标题】:Launchd script to auto-mount AFP share启动脚本以自动挂载 AFP 共享
【发布时间】:2011-08-05 07:34:58
【问题描述】:

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

【问题讨论】:

    标签: macos launchd afp


    【解决方案1】:

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

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

    据我所知,每次您的网络发生变化时,该目录中的文件都会更新。所以这会给你你的第一个触发器。另一个要查看的 plist 项目是“PathState”。 launchd.plist man page 有以下文档:

    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.
    

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 2017-08-11
      • 2016-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多