0

I am trying to run a ruby program as a cron. I have figured out how to run the ruby program from a launchd The problem is that I don't know how to say "Run the job once every Sunday". Below is 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>EnableGlobbing</key>
    <false/>
    <key>Label</key>
    <string>ScratchFolders.job</string>
    <key>ProcessType</key>
    <string>Background</string>
    <key>Program</key>
    <string>/usr/local/rvm/wrappers/scratch-monitor/ruby</string>
    <key>ProgramArguments</key>
    <array>
        <string></string>
        <string>scratch-clean.rb</string>
    </array>
    <key>StandardErrorPath</key>
    <string>/tmp/ScratchFolders.job.err</string>
    <key>StandardOutPath</key>
    <string>/tmp/ScratchFolders.job.out</string>
    <key>StartCalendarInterval</key>
    <array>
        <dict>
            <key>Weekday</key>
            <integer>7</integer>
        </dict>
    </array>
    <key>WorkingDirectory</key>
    <string>~/automation-scripts/</string>
</dict>
</plist>
0

1 Answer 1

1

The first and biggest problem is that you are using the Program and ProgramArguments keys wrong. They're rather confusing because they correspond to the first two arguments to execvp, and unless you understand execvp, you won't understand these keys properly. But there's a simple way to do it in most cases: don't use Program, and put the full path to the program in the first string in ProgramArguments:

<key>ProgramArguments</key>
<array>
    <string>/usr/local/rvm/wrappers/scratch-monitor/ruby</string>
    <string></string>
    <string>scratch-clean.rb</string>
</array>

(Note: I'm assuming you're trying to pass a blank first argument to the program -- if not, remove the <string></string>.)

The second problem I see is the WorkingDirectory key -- I'm pretty sure it won't expand ~ in this context, so you need to specify the full path explicitly:

<key>WorkingDirectory</key>
<string>/Users/chan/automation-scripts/</string>

Finally, I think you may also need to specify the hour and minute to start it at:

<key>StartCalendarInterval</key>
<dict>
    <key>Weekday</key>
    <integer>7</integer>
    <key>Hour</key>
    <integer>3</integer>
    <key>Minute</key>
    <integer>15</integer>
</dict>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .