【问题标题】:Mac daemon is not running but is present in launchctl listMac 守护程序未运行但存在于 launchctl 列表中
【发布时间】:2019-08-28 19:54:21
【问题描述】:

这是我第一次尝试创建守护进程,所以如果我说一些菜鸟的话,请多多包涵。

我使用 AppleScript 编写了一个测试脚本。最终,这将更加强大,并成为会议播音员和其他一些通知,以开始我的一天。这是现在的脚本:

say "Hello Steve, the job has launched!"

这是列表:

我在 /Library/LaunchDaemons 中将它保存为 local.jeeves.plist。我通过目视找到它并运行来确认它在那里:

launchctl list

跑步

 launchctl list | grep local.Jeeves

也证实了它的存在。

我确认Program 键引用的脚本在该目录中。它也可以从 AppleScript 运行它

回到 plist。我通过运行加载它:

launchctl load /Library/LaunchDaemons/local.jeeves.plist

终端没有产生任何错误。

如果我跑步:

launchctl start local.jeeves

launchctl start local.Jeeves

没有结果。没有错误,但脚本没有运行。

所以我对我的 system.log 进行了一些挖掘,发现了这些错误:

Aug 28 15:26:17 Steves-MBP com.apple.xpc.launchd[1] (com.apple.xpc.launchd.user.domain.501.100009.Aqua): Could not read path: path = /Users/xxxxxxx/Library/LaunchDaemons/local.jeeves.plist, error = 2: No such file or directory
Aug 28 15:27:33 Steves-MBP com.apple.xpc.launchd[1] (com.apple.xpc.launchd.user.domain.501.100009.Aqua): Could not read path: path = /Users/xxxxxxxx/Library/LaunchDaemons/local.jeeves.plist, error = 2: No such file or directory
Aug 28 15:28:05 Steves-MBP com.apple.xpc.launchd[1] (local.Jeeves[14803]): Could not find and/or execute program specified by service: 13: Permission denied: /Users/xxxxxxx/Scripts/AppleScripts/testScript.scpt
Aug 28 15:28:05 Steves-MBP com.apple.xpc.launchd[1] (local.Jeeves[14803]): Service setup event to handle failure and will not launch until it fires.
Aug 28 15:28:05 Steves-MBP com.apple.xpc.launchd[1] (local.Jeeves[14803]): Service exited with abnormal code: 78

所以现在我知道问题所在了。这是目录问题的权限还是根本找不到目录?

【问题讨论】:

    标签: scripting applescript launchctl


    【解决方案1】:

    几点...首先,如果您想从 /Library/LaunchDaemons 加载作业,您将需要管理员权限,这意味着您可能必须使用 sudo launchctl 才能启动它。这是您看到的问题的一部分(可能是日志抱怨“/Users/xxxxxxx/Library/LaunchDaemons”的原因:您未指定且不存在的位置......)。

    其次,LaunchDaemons 是完全不露面的:它们是后台任务,通常在用户登录会话之外运行,因此不应访问语音合成器或窗口服务器等界面元素。如果您的意思是这是一个公告服务,您应该将其作为 LaunchAgent 运行,而不是作为 LaunchDaemon。如果您将 plist 文件移动到 '/Users/xxxxxxx/Library/LaunchAgents' 并尝试再次加载它,一切都会正常运行。

    【讨论】:

      猜你喜欢
      • 2019-08-13
      • 2013-11-17
      • 1970-01-01
      • 2022-08-22
      • 1970-01-01
      • 1970-01-01
      • 2018-07-11
      • 2016-07-22
      • 2012-05-19
      相关资源
      最近更新 更多