-1

这是我第一次尝试创建守护进程,所以如果我说一些菜鸟的话,请耐心等待。

我使用 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

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

4

1 回答 1

0

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

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

于 2019-08-28T20:58:10.407 回答