【问题标题】:Starting Automator Script with LaunchAgent使用 LaunchAgent 启动 Automator 脚本
【发布时间】:2023-03-31 10:25:02
【问题描述】:

我通过 Automator 建立了一个作业来清除下载文件夹并清空垃圾箱。当我通过双击启动创建的应用程序时,它会正确启动。但它必须转移到我们公司的其他计算机上,我不想给用户启动应用程序的工作。 所以我创建了这个 LaunchAgent 脚本来启动应用程序。

    <?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>com.herpag.aufraeumen.plist</string>
        <key>ProgramArguments</key>
        <array>
            <string>/Users/hansthiele/Applications/Aufraeumen.app</string>
        </array>
        <key>StartCalendarInterval</key>
        <dict>
            <key>Minute</key>
            <integer>45</integer>
            <key>Hour</key>
            <integer>13</integer>
        </dict>
    </dict>
    </plist>

我现在的问题是,控制台告诉我作业已启动,但没有任何反应。下载未清除,垃圾箱仍满。 error.log 也是空的。

【问题讨论】:

    标签: macos launchd


    【解决方案1】:

    有两个问题:

    1. Label 参数必须在没有 .plist 扩展名的情况下指定。
    2. 路径必须代表可执行文件而不是应用程序容器。对于 Automator 应用程序,可执行文件名为 Application Stub(与 AppleScript 应用程序中的 Applet 不同)。假设hansthiele 是当前用户的真实短用户名。

    试试

    <?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>com.herpag.aufraeumen</string>
        <key>ProgramArguments</key>
        <array>
            <string>/Users/hansthiele/Applications/Aufraeumen.app/Contents/MacOS/Application Stub</string>
        </array>
        <key>StartCalendarInterval</key>
        <dict>
            <key>Minute</key>
            <integer>45</integer>
            <key>Hour</key>
            <integer>13</integer>
        </dict>
    </dict>
    </plist>
    

    【讨论】:

    • 我尝试了更改,但现在我在终端中加载或卸载脚本时收到一条消息“找不到指定的服务”。仅当标签包含 .plist 时,我才收到消息。
    • 在launchctl load 行中必须包含plist 扩展名,但不能包含在正确的列表文件中。
    • 现在我发现了错误。它不是 .plist,但路径中缺少一些东西。它必须是“内容/MacOS/应用程序存根”。现在它工作正常。感谢您的帮助!
    • 对不起,那是我的错误。当然可执行文件总是在文件夹MacOS
    猜你喜欢
    • 2019-12-24
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 2020-06-05
    • 2020-02-28
    • 2017-06-06
    • 2014-05-21
    • 1970-01-01
    相关资源
    最近更新 更多