launchd 启动代理不执行命令

发布于 2025-01-03 22:07:11 字数 2370 浏览 1 评论 0原文

我在工作时在 Mac 上使用 Skype 和 Adium 客户端。我有两个脚本(Ruby,如果重要的话),start_chatskill_chats 启动/终止这两个应用程序。这些脚本都是可执行的,并且可以在命令行中正常工作。我曾经在 Snow Leopard 中使用 cron 在预定时间运行这些脚本:当我进入办公室时,start_chats 在 8:00 运行,并使用 kill_chats 杀死它们(因此,在我离开办公室后的 6:00 (18:00) 处将我从所有连接的帐户中注销。

由于我最近得到了一台装有 Lion 的新机器,因此 cron 的行为非常不稳定,而且通常根本不执行其作业(我在同一个 crontab 中还有其他作业)。因此,为了跟上技术的发展,我决定尝试使用 launchd plists 重新设计它。我已经浏览了许多“教程”以及如何构建 plist 来对我的脚本进行简单的基于时钟的执行。大多数这些教程的问题在于,它们并没有真正告诉您创建 plist 后要做什么。这是我的示例 kill_chats plist (在 这篇文章):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>local.me.kill_chats</string>
    <key>OnDemand</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/me/bin/kill_chats</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>18</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
</dict>
</plist>

是的,它被命名为 local.me.kill_chats.plist,我把它放在我的~/Library/LaunchAgents/ 目录。请注意,我也尝试过使用 Program 键,但这也不起作用。如果我运行

$> launchctl load ~/Library/LaunchAgents/local.me.kill_chats.plist

它,它会说列表已经加载,实际上我可以在

$> launchctl list | egrep kill_chats
   -    0   local.me.kill_chats

但是当我的系统时钟达到 plist 中指定的时间时,我的 kill_chats 脚本没有运行。当然,我不会每次都等到 18:00 才测试它,所以我将其更改为比当前时间提前几分钟,但它仍然不执行脚本。我什至尝试过 Lingon (较旧的免费版本),但似乎没有任何效果。

我做错了什么吗?我的 plist 有问题吗?正如我所说,我浏览了许多不同的网站(甚至许多 Stackexchange 帖子),我的列表似乎是正确的。我只是不确定如何让“它”“使用”我的列表。任何帮助将不胜感激。

(注意:管理员,请随意将其迁移到 Apple超级用户 如有必要)

I use the Skype and Adium clients on my Mac at work. I have two scripts (Ruby, if it matters), start_chats and kill_chats that start/kill both applications. These scripts are both executable and work fine from the command line. I used to use cron in Snow Leopard to run these scripts at scheduled times: start_chats at 8:00 when I come in to my office, and kill_chats to kill them (thus, logging me out of all connected accounts) at 6:00 (18:00) after I leave my office.

Since I recently got a new machine with Lion on it, cron acts really flaky and more often than not, does not execute its jobs at all (I have other jobs in the same crontab). So, in trying to keep up with technology, I decided I'd try to rework this using launchd plists. I've looked through many "tutorials" and whatnot on how to construct a plist to do a simple clock-based execution of my scripts. The problem with most of these tutorials is that they don't really tell what to do after you've created the plist. Here is my sample kill_chats plist (built with help from this post):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>local.me.kill_chats</string>
    <key>OnDemand</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/me/bin/kill_chats</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>18</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
</dict>
</plist>

Yes, it is named local.me.kill_chats.plist and I put it in my ~/Library/LaunchAgents/ directory. Note that I've also tried to use the Program key as well, but that didnt' work either. If I run

gt; launchctl load ~/Library/LaunchAgents/local.me.kill_chats.plist

it says the list is already loaded, and indeed I can see it in

gt; launchctl list | egrep kill_chats
   -    0   local.me.kill_chats

But when my system clock hits the time specified in the plist, my kill_chats script is not being run. Of course I'm not waiting until 18:00 to test it every time, so I change it to a few minutes ahead of whatever the current time is, but it's still not executing the script. I've even tried Lingon (the older, free version), but nothing seems to work.

Am I doing something wrong? Is something wrong with my plist? As I said, I've looked through a bunch of different sites (even numerous Stackexchange posts) and my list seems to be correct. I'm just not sure how to make "it" "use" my list. Any help would be greatly appreciated.

(Note: admins, feel free to migrate this to Apple or Superuser if necessary)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文