What's the difference between 'Day' and 'Weekday' in launchd StartCalendarInterval?
Asked Answered
F

3

17

I'm working with launchd to run some automated tasks, and I was wondering what the difference is between 'Day' and 'Weekday'.

According to http://discussions.apple.com/thread.jspa?threadID=1361809 there is a 'subtle' difference that can cause launchd to misbehave.

Ultimately, I'd like to have a plist that runs every weekday (Mon - Fri) at 8am, but I don't know how to get the cron equivalent of

0 8 * * 1-5
Forrest answered 25/8, 2010 at 23:18 Comment(3)
I can only imagine that day = {Sun Mon Tue Wed Thu Fri Sat} and weekday = {Mon Tue Wed Thu Fri}...Dennett
Also, that's a two-year-old thread.Dennett
But developer.apple.com/mac/library/documentation/Darwin/Reference/… specifies: Day <integer> The day on which this job will be run. Weekday <integer> The weekday on which this job will be run (0 and 7 are Sunday). So do Day and Weekday just have different integer values for days? It's certainly not clear to me from the documentation.Forrest
L
33

Day is the day of the month.

Weekday is the day of the week (0 and 7 == Sunday).

For you, you need:

<key>StartCalendarInterval</key>
<array>
    <dict>
        <key>Weekday</key>
        <integer>1</integer>
        <key>Hour</key>
        <integer>8</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
    <dict>
        <key>Weekday</key>
        <integer>2</integer>
        <key>Hour</key>
        <integer>8</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
    <dict>
        <key>Weekday</key>
        <integer>3</integer>
        <key>Hour</key>
        <integer>8</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
    <dict>
        <key>Weekday</key>
        <integer>4</integer>
        <key>Hour</key>
        <integer>8</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
    <dict>
        <key>Weekday</key>
        <integer>5</integer>
        <key>Hour</key>
        <integer>8</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
</array>

Not quite as elegant as cron...

Lefty answered 25/8, 2010 at 23:50 Comment(0)
G
1

try this too. Working for me!

     <key>StartCalendarInterval</key>

    <dict>

            <key>Minute</key>

            <integer>00</integer>

            <key>Hour</key>

            <integer>22</integer>

            <key>Weekday</key>

            <integer>12345</integer>

    </dict>
Gilstrap answered 20/3, 2013 at 10:4 Comment(2)
Under 10.9 I get: The interval for key "Weekday" is not between 0 and 7 (inclusive) In the Console :(Hertzfeld
This does not work. See: apple.stackexchange.com/a/249452/242297Unstop
F
-1

You should be able to use hyphens to specify ranges as well:

<key>StartCalendarInterval</key>
<array>
    <dict>
        <key>Weekday</key>
        <integer>1-5</integer>
        <key>Hour</key>
        <integer>8</integer>
        <key>Minute</key>
        <integer>0</integer>
    </dict>
</array>

I didn't test this though. (Source: http://www.launchd.info/)

Faultfinder answered 1/5, 2017 at 1:53 Comment(1)
This does not work with launchd. The linked website offers information for a proprietary product called LaunchControl that allows the user to specify intervals in a "cron-like" syntax. See "Cron-style specifications" section on the "Configuration" tab of the page: "Some intervals are very tedious to specify in launchd. [...] A quick example: You want to run a program every five minutes between 20:00 and 23:00. In launchd you have to list all 36 matching timestamps [...] LaunchControl allows you to generate this list from the equivalent cron-style specification [...]"Unstop

© 2022 - 2024 — McMap. All rights reserved.