27

I configured the launchd to start a command at 18pm every day on my mac pro,but it was not working.

I want to check if the launchd has run the command. I tried the system console, found no anything valuable.

my mac os version is mac os x 10.8.3

My plist file:

<?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>mytask</string>
    <key>Program</key>
    <string>/opt/local/bin/node</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/xxx/My/task.js</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>18</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
    <key>StandardOutPath</key>
    <string>/Users/xxx/launchd.stdout.log</string>
    <key>StandardErrorPath</key>
    <string>/Users/xxx/launchd.stderr.log</string>
</dict>
</plist>
hywl51
  • 551
  • 1
  • 5
  • 13
  • 1
    I would point out to those (like me) that didnt notice, but the executable is fully qualified `/opt/local/bin/node`. This is likely necessary because launchd has [different environment configuration](https://discussions.apple.com/thread/3244126?tstart=0) than a user would, despite the script being [run under the user's account](https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html#pageTitle). – Jeff Aug 26 '16 at 14:31

1 Answers1

33

You defined StartCalendarInterval, so the job has been executed when it was loaded and it will be executed every day at 18:00.

Query launchd(8) to find out its exit status:

launchctl list | grep mytask

this will return a line line this:

<pid> <status> mytask

When pid is a number, the job is currently running. Otherwise have a look at status, which is the exit code of the program, node in your case. An exit code of 0 means either that the program was finished successfully or that is has not been started yet. Positive numbers are returned for program errors, while negative ones mean that the job has terminated due to a signal.

I assume the job failed. You may want to check the programs standard output/error. Specify StandardOutPath and StandardErrorPath to do that. The content of these files will likely tell you why the program failed.

LCC
  • 1,175
  • 1
  • 10
  • 11
  • I ran launchctl list and got status 0. I add StandardOutPath and StandardErrorPath to the plist as above,but no file was found after I run the task with launchctl start. So I feel it seems the task has not been started yet. – hywl51 May 25 '13 at 10:23
  • 4
    Make sure you reload the job definition (`unload`, then `load`) after altering it. Just modifying the file and issuing a start command won't do the job. – LCC May 26 '13 at 08:53
  • Thanks.After I upload and load the task,StandardOutPath and StandardErrorPath work fine. – hywl51 May 26 '13 at 11:38
  • 3
    After I remove "Program" from plist and move the /opt/local/bin/node into ProgramArguments ,the task run successfully with launchd start. – hywl51 May 26 '13 at 11:41