Why aren't weekday scheduled applescripts working?

  Collisio-Adolebitque 14:48 13 Jul 2018
Locked

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 1: /Users/$USER/Documents/dev/applescripts/opencomms_apps.scpt

# 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

Script 2: /Users/$USER/Documents/dev/applescripts/closecomms_apps.scpt

# Close messaging & comms apps.
tell application "Microsoft Outlook.app"
    if (exists window 1) then quit
end tell
tell application "Slack.app"
    quit
end tell
tell application "Skype.app"
    quit
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

    Disabled

    Label
    com.open.comms.apps
    KeepAlive

    RunAtLoad

    Program
    /usr/bin/osascript
    ProgramArguments

        osascript
        /Users/$USER/Documents/dev/apple_scripts/open_comms_apps.scpt

    StartCalendarInterval


            Weekday
            1
            Hour
            9
            Minute
            0


            Weekday
            1
            Hour
            13
            Minute
            0


            Weekday
            1
            Hour
            16
            Minute
            30


            Weekday
            2
            Hour
            9
            Minute
            0


            Weekday
            2
            Hour
            13
            Minute
            0


            Weekday
            2
            Hour
            16
            Minute
            30


            Weekday
            3
            Hour
            9
            Minute
            0


            Weekday
            3
            Hour
            13
            Minute
            0


            Weekday
            3
            Hour
            16
            Minute
            30


            Weekday
            4
            Hour
            9
            Minute
            0


            Weekday
            4
            Hour
            13
  Collisio-Adolebitque 15:00 13 Jul 2018

Forum appears to cut off most of the thread and removed the plist tags. In a nutshell, the scheduled tasks are't working.

    Disabled

    Label
    com.open.comms.apps
    KeepAlive

    RunAtLoad

    Program
    /usr/bin/osascript
    ProgramArguments

        osascript
        /Users/$USER/Documents/dev/apple_scripts/open_comms_apps.scpt

    StartCalendarInterval


            Weekday
            1
            Hour
            9
            Minute
            0


            Weekday
            1
            Hour
            13
            Minute
            0


            Weekday
            1
            Hour
            16
            Minute
            30


            Weekday
            2
            Hour
            9
            Minute
            0


            Weekday
            2
            Hour
            13
            Minute
            0


            Weekday
            2
            Hour
            16
            Minute
            30


            Weekday
            3
            Hour
            9
            Minute
            0


            Weekday
            3
            Hour
            13
            Minute
            0


            Weekday
            3
            Hour
            16
            Minute
            30


            Weekday
            4
            Hour
            9
            Minute
            0


            Weekday
            4
            Hour
            13
            Minute
            0


            Weekday
            4
            Hour
            16
            Minute
            30


            Weekday
            5
            Hour
            9
            Minute
            0


            Weekday
            5
            Hour
            13
            Minute
            0


            Weekday
            5
            Hour
            16
            Minute
            30

Scheduled task 2: /Users/$USER/Library/LaunchAgents/com.close.comms.apps.plist

  Collisio-Adolebitque 15:00 13 Jul 2018

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:

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

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

launchctl start /Users/$USER/Library/LaunchAgents/com.open.comms.apps.plist
launchctl start /Users/$USER/Library/LaunchAgents/com.close.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?

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Huawei MateBook X Pro (2019) review

Nvidia’s Gaugan tech turns simple colour blocks into realistic landscapes

New AirPods 2 launch: Release date, price, features & specs

AirPower : date de sortie, prix et fiche technique