0

I would like LaunchD to launch a script every other week. The following works fine for every week, but how can I schedule it to only run every other week?

<?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>Program</key>
        <string>/scripts/autoSample</string>
        <key>AbandonProcessGroup</key>
        <true/>
        <key>Debug</key>
        <true/>
        <key>StartCalendarInterval</key>
        <dict>
                <key>Weekday</key>
                <integer>0</integer>
                <key>Minute</key>
                <integer>40</integer>
                <key>Hour</key>
                <integer>8</integer>
        </dict>
        <key>Label</key>
        <string>autoSample</string>
</dict>
</plist>
1

How about using a StartInterval of 2 weeks (1209600 secs) instead?

<?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>Program</key>
        <string>/scripts/autoSample</string>
        <key>AbandonProcessGroup</key>
        <true/>
        <key>Debug</key>
        <true/>        
        <key>StartInterval</key>
        <integer>1209600</integer>
        <key>Label</key>
        <string>autoSample</string>
</dict>
</plist>
2
  • If I understand correctly that would only work if I timed the loading correctly. A reboot would also break it, wouldn't it? -- Thanks though – Dave Albert Apr 5 '13 at 9:25
  • Yes, you're right. Here's another idea: what about your original StartCalendarInterval, then adding a ThrottleInterval of over 1 week? – Colin Pickard Apr 5 '13 at 9:34
0

You could add something like this to the start of the program:

(($(date +%V) % 2 == 0)) && exit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.