SOLVED Mac OS High Sierra weekday scheduled tasks with launchd aren't working, why?

Joined
Jul 13, 2018
Messages
1
Reaction score
0
In an effort to improve my productivity and reduce distractions (after listening to *'Deep Work'* by Cal Newport on Audible), I decided to automatically launch and close email and IM apps on my Mac at certain times of day, allowing me to focus on productive work the rest of the time. I cobbled together 2 apple-scripts that work fine from the Terminal:

Script: /Users/$USER/Documents/dev/apple_scripts/open_comms_apps.scpt

Code:
# Open messaging & comms apps.
    tell application "Microsoft Outlook.app"
        if not (exists window 1) then activate
    end tell
    tell application "Slack.app"
        if not (exists window 2) then launch
    end tell
    tell application "Skype.app"
        launch
    end tell

NB: I had already assigned Outlook, Slack and Skype to their own desktops.

-------

What I wanted to do was open them 3 times a day on weekdays only, so I created the following plist files for launchd.

Scheduled task 1: /Users/$USER/Library/LaunchAgents/com.open.comms.apps.plist

Code:
<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Disabled</key>
       <false/>
       <key>Label</key>
        <string>com.open.comms.apps</string>
        <key>KeepAlive</key>
        <false/>
        <key>RunAtLoad</key>
        <true/>
        <key>Program</key>
        <string>/usr/bin/osascript</string>
        <key>ProgramArguments</key>
        <array>
            <string>osascript</string>
            <string>/Users/$USER/Documents/dev/apple_scripts/open_comms_apps.scpt</string>
        </array>
       <key>StartCalendarInterval</key>
       <array>
           <dict>
               <key>Weekday</key>
               <integer>1</integer>
               <key>Hour</key>
               <integer>9</integer>
               <key>Minute</key>
               <integer>0</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>1</integer>
               <key>Hour</key>
               <integer>13</integer>
               <key>Minute</key>
               <integer>0</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>1</integer>
               <key>Hour</key>
               <integer>16</integer>
               <key>Minute</key>
               <integer>30</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>2</integer>
               <key>Hour</key>
               <integer>9</integer>
               <key>Minute</key>
               <integer>0</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>2</integer>
               <key>Hour</key>
               <integer>13</integer>
               <key>Minute</key>
               <integer>0</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>2</integer>
               <key>Hour</key>
               <integer>16</integer>
               <key>Minute</key>
               <integer>30</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>3</integer>
               <key>Hour</key>
               <integer>9</integer>
               <key>Minute</key>
               <integer>0</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>3</integer>
               <key>Hour</key>
               <integer>13</integer>
               <key>Minute</key>
               <integer>0</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>3</integer>
               <key>Hour</key>
               <integer>16</integer>
               <key>Minute</key>
               <integer>30</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>4</integer>
               <key>Hour</key>
               <integer>9</integer>
               <key>Minute</key>
               <integer>0</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>4</integer>
               <key>Hour</key>
               <integer>13</integer>
               <key>Minute</key>
               <integer>0</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>4</integer>
               <key>Hour</key>
               <integer>16</integer>
               <key>Minute</key>
               <integer>30</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>5</integer>
               <key>Hour</key>
               <integer>9</integer>
               <key>Minute</key>
               <integer>0</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>5</integer>
               <key>Hour</key>
               <integer>13</integer>
               <key>Minute</key>
               <integer>0</integer>
           </dict>
           <dict>
               <key>Weekday</key>
               <integer>5</integer>
               <key>Hour</key>
               <integer>16</integer>
               <key>Minute</key>
               <integer>30</integer>
           </dict>
       </array>
    </dict>
    </plist>


NB: I tried this with hard-coded username in the file paths and the $USER system variable.

-------

I amended the permissions on the scripts and loaded the plist files via terminal as follows:

Code:
chmod 755 /Users/$USER/Documents/dev/apple_scripts/open_comms_apps.scpt
launchctl load -w /Users/$USER/Library/LaunchAgents/com.open.comms.apps.plist

-------

As many might expect, this hasn't worked and when I try to start the scheduled tasks manually:

Code:
launchctl start /Users/$USER/Library/LaunchAgents/com.open.comms.apps.plist

Nothing happens.

Can anyone out there (with more than my <1 days experience with apple-script and launchd), please advise how to get this to work?
 

Cory Cooper

Moderator
Joined
May 19, 2004
Messages
11,105
Reaction score
497
Hello and welcome.

I don't have much experience with Automator/AppelScript either. Maybe the folks over at MacScripter can shed some light.

Let us know how that goes,

C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top