Bash脚本无法通过启动的Mac OS运行

时间:2019-11-27 00:18:07

标签: bash macos launchd macos-catalina

当我直接通过终端尝试以下脚本时,我的以下脚本运行良好:

count=`ls -l /Users/ben/Downloads/*.png 2>/dev/null | wc -l`
echo $count`

它返回正确的计数为1!

但是当我通过启动运行它时,它总是返回零!

这是我启动的脚本

<?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.ben.Cleaner</string>
  <key>ProgramArguments</key>
  <array>
        <string>/bin/sh</string>
        <string>/Users/ben/Scripts/clean.sh</string>
  </array>
  <key>StartCalendarInterval</key>
  <dict>
    <key>Hour</key>
    <integer>22</integer>
  </dict>
  <key>StandardErrorPath</key>
  <string>/tmp/AlTest12.err</string>
  <key>StandardOutPath</key>
  <string>/tmp/AlTest12.out</string>
</dict>
</plist>

知道为什么它无法通过启动吗?我在Mac OS Catalina上运行。

1 个答案:

答案 0 :(得分:0)

尝试将时间间隔更改为以下结构:

<key>StartInterval</key>
<integer>1800</integer>

此部分:

<key>StartCalendarInterval</key>
  <dict>
    <key>Hour</key>
    <integer>22</integer>
  </dict>

不适用于我,将所有内容转换为秒,也许对我有帮助。