launchd run command every minute of a specific hour
Edit start
You got it all correct except for enclosing your <dict>
element inside an <array>
element. Your script will run every minute from 21:00 to 21:59 with the following as your StartCalendarInterval
key :
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>21</integer>
</dict>
</array>
If you wanted your script to run every minute, every hour, every day, every year, the following would be the correct (but certainly not obvious) syntax for that:
<key>StartCalendarInterval</key>
<array>
<dict/>
</array>
My original answer (below) would also work, but it's clearly much more tedious! OTOH, if one needed every other minute, or certain minutes, it might be useful.
Edit end
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Minute</key>
<integer>0</integer>
</dict>
<dict>
<key>Minute</key>
<integer>1</integer>
</dict>
<dict>
<key>Minute</key>
<integer>2</integer>
</dict>
<dict>
<key>Minute</key>
<integer>3</integer>
</dict>
<dict>
<key>Minute</key>
<integer>4</integer>
</dict>
... ad nauseum ...
<dict>
<key>Minute</key>
<integer>59</integer>
</dict>
</array>
To answer your question, "Why is this not running every minute?", it's only because you failed to enclose <dict>
inside <array>
. FWIW, it seems very odd to me also, and WHY it's designed this way is an answer I'd like to hear myself. But then I guess Apple could use the defense that "just because the semantics are similar does not mean the syntax is."
I think this is a bug in launchd
.
If I take out the hour designation, it fires every minute.
But if I restrict the plist to only 9pm, then it only fires once.
Update
This is what I tried (with the hour changed to ’12’ because that’s the current hour when I tried to test it).
The ’test.txt’ file never gets created.
<?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.tjluoma.everyminute</string>
<key>Program</key>
<string>/bin/date</string>
<key>StandardOutPath</key>
<string>/Users/tjluoma/Desktop/test.txt</string>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>12</integer>
</dict>
</array>
</dict>
</plist>
This does create/update the file every minute
<?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.tjluoma.everyminute</string>
<key>Program</key>
<string>/bin/date</string>
<key>StandardOutPath</key>
<string>/Users/tjluoma/Desktop/test.txt</string>
<key>StartCalendarInterval</key>
<array>
<dict/>
</array>
</dict>
</plist>