launchd plist format for running a command at a specific time on a weekday I'm trying to run a command at 10 minutes after 2am every weekday only.  In my launchd .plist file, how can I specify this?  

I don't want it to run every 2 hours and 10 minutes, just once every weekday at the specified time.
There are a few caveats with creating launchd .plist files.  I'll summarize them below:


Each Weekday must be a  entry specified in an  placed in the StartCalendarInterval dictionary entry.
Weekdays go from 1 to 5.  Sunday is 0 and 7 (I know, right?)
You have to know how you want your item to run and place the .plist in the appropriate directories/folders:


~/Library/LaunchAgents - Specific to the user.  Will run when the user is logged in.
/Library/LaunchAgents - Specific to all users.  Will run when the user(s) is(are) logged in.
/Library/LaunchDaemons - Runs regardless if user(s) is(are) logged in.  Must use sudo to load .plist



My preference is #3 (load as a LaunchDaemon) so my script will get executed whether I am logged in or not.  When using as a LaunchDameon, you must use sudo to load the .plist:

sudo lauchctl load com.user.fileCleanup.plist

Note:  As for the naming convention in my example, I like to use com.user.&lt; name of my script &gt;.plist  This helps me in identifying and debugging any issues should they arise and keeps with the Apple naming convention of com.apple.some-app.plist  This is entirely optional on your part.

Below is a script that I am using to clean up work files (I modified it for your specific time parameters). You can edit this file with your favorite text editor (I use Komodo Edit), but TextEdit or even nano or vi from the command line will work.



&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;com.user.fileCleanup&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/Users/allan/Documents/Scripts/Unix/fileCleanup.sh&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;StartCalendarInterval&lt;/key&gt;
    &lt;!--  Weekdays are 1 - 5; Sunday is 0 and 7   --&gt;
    &lt;array&gt;
        &lt;dict&gt;
            &lt;key&gt;Weekday&lt;/key&gt;
            &lt;integer&gt;1&lt;/integer&gt;
            &lt;key&gt;Hour&lt;/key&gt;
            &lt;integer&gt;2&lt;/integer&gt;
            &lt;key&gt;Minute&lt;/key&gt;
            &lt;integer&gt;10&lt;/integer&gt;
        &lt;/dict&gt;
        &lt;dict&gt;
            &lt;key&gt;Weekday&lt;/key&gt;
            &lt;integer&gt;2&lt;/integer&gt;
            &lt;key&gt;Hour&lt;/key&gt;
            &lt;integer&gt;2&lt;/integer&gt;
            &lt;key&gt;Minute&lt;/key&gt;
            &lt;integer&gt;10&lt;/integer&gt;
        &lt;/dict&gt;
        &lt;dict&gt;
            &lt;key&gt;Weekday&lt;/key&gt;
            &lt;integer&gt;3&lt;/integer&gt;
            &lt;key&gt;Hour&lt;/key&gt;
            &lt;integer&gt;2&lt;/integer&gt;
            &lt;key&gt;Minute&lt;/key&gt;
            &lt;integer&gt;10&lt;/integer&gt;
        &lt;/dict&gt;
        &lt;dict&gt;
            &lt;key&gt;Weekday&lt;/key&gt;
            &lt;integer&gt;4&lt;/integer&gt;
            &lt;key&gt;Hour&lt;/key&gt;
            &lt;integer&gt;2&lt;/integer&gt;
            &lt;key&gt;Minute&lt;/key&gt;
            &lt;integer&gt;10&lt;/integer&gt;
        &lt;/dict&gt;
        &lt;dict&gt;
            &lt;key&gt;Weekday&lt;/key&gt;
            &lt;integer&gt;5&lt;/integer&gt;
            &lt;key&gt;Hour&lt;/key&gt;
            &lt;integer&gt;2&lt;/integer&gt;
            &lt;key&gt;Minute&lt;/key&gt;
            &lt;integer&gt;10&lt;/integer&gt;
        &lt;/dict&gt;
    &lt;/array&gt;

&lt;/dict&gt;
&lt;/plist&gt;


Bonus Footage....

This next part is optional...

So that I can get some feedback that my scripts executed and what the result was, I created a small AppleScript function that invokes the display notification (it's quite simple for my needs, but obviously could be improved).

on run argv

    set Message to item 1 of argv
    set Title to item 2 of argv
    set aud to item 3 of argv
    set STitle to "Terminal"
    set Snd to "Blow.aiff"


    if (aud = "sound") then

        display notification Message with title Title subtitle STitle sound name Snd
    else
        display notification Message with title Title subtitle STitle
    end if

end run


Within my script, I check for success or failure, depending on what that is (i.e. a file existing in a particular directory), it will generate a notification.  If not, another notification, but this time with sound!

#!/bin/bash
if [ -f "$SOURCE" ]
then
    scp -q "$SOURCE" "$TARGET"
    osascript $ASCRIPT_DIR/notify.scpt "Podcast Transfered successfully" "$TITLE -- SUCCESS" "nosound"
else
    osascript $ASCRIPT_DIR/notify.scpt "The file $TARGET does not exist" "$TITLE -- ERROR" "sound"
fi


Here's the sample output: