Geplante Aufgaben für Mac OS High Sierra-Wochentage mit launchd funktionieren nicht. Warum?

424
Collisio-Adolebitque

Um meine Produktivität zu verbessern und Ablenkungen zu reduzieren (nachdem ich 'Deep Work' von Cal Newport on Audible angehört hatte), entschied ich mich, E-Mail- und IM-Apps zu bestimmten Tageszeiten auf meinem Mac automatisch zu starten und zu schließen, sodass ich mich darauf konzentrieren kann den Rest der Zeit produktive Arbeit. Ich habe 2 Apple-Skripte zusammengeschustert, die vom Terminal aus gut funktionieren:

Skript 1: /Users/$USER/Documents/dev/apple_scripts/open_comms_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 

Skript 2: /Users/$USER/Documents/dev/apple_scripts/close_comms_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 

Hinweis: Ich hatte bereits Outlook, Slack und Skype ihren eigenen Desktops zugewiesen.


Was ich wollte, war, sie nur an Wochentagen dreimal am Tag zu öffnen, also erstellte ich die folgenden plist-Dateien für launchd.

Geplanter Task 1: /Users/$USER/Library/LaunchAgents/com.open.comms.apps.plist

<?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> 

Geplanter Task 2: /Users/$USER/Library/LaunchAgents/com.close.comms.apps.plist

<?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.close.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/close_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>30</integer> </dict> <dict> <key>Weekday</key> <integer>1</integer> <key>Hour</key> <integer>13</integer> <key>Minute</key> <integer>30</integer> </dict> <dict> <key>Weekday</key> <integer>1</integer> <key>Hour</key> <integer>16</integer> <key>Minute</key> <integer>45</integer> </dict> <dict> <key>Weekday</key> <integer>2</integer> <key>Hour</key> <integer>9</integer> <key>Minute</key> <integer>30</integer> </dict> <dict> <key>Weekday</key> <integer>2</integer> <key>Hour</key> <integer>13</integer> <key>Minute</key> <integer>30</integer> </dict> <dict> <key>Weekday</key> <integer>2</integer> <key>Hour</key> <integer>16</integer> <key>Minute</key> <integer>45</integer> </dict> <dict> <key>Weekday</key> <integer>3</integer> <key>Hour</key> <integer>9</integer> <key>Minute</key> <integer>30</integer> </dict> <dict> <key>Weekday</key> <integer>3</integer> <key>Hour</key> <integer>13</integer> <key>Minute</key> <integer>30</integer> </dict> <dict> <key>Weekday</key> <integer>3</integer> <key>Hour</key> <integer>16</integer> <key>Minute</key> <integer>45</integer> </dict> <dict> <key>Weekday</key> <integer>4</integer> <key>Hour</key> <integer>9</integer> <key>Minute</key> <integer>30</integer> </dict> <dict> <key>Weekday</key> <integer>4</integer> <key>Hour</key> <integer>13</integer> <key>Minute</key> <integer>30</integer> </dict> <dict> <key>Weekday</key> <integer>4</integer> <key>Hour</key> <integer>16</integer> <key>Minute</key> <integer>45</integer> </dict> <dict> <key>Weekday</key> <integer>5</integer> <key>Hour</key> <integer>9</integer> <key>Minute</key> <integer>30</integer> </dict> <dict> <key>Weekday</key> <integer>5</integer> <key>Hour</key> <integer>13</integer> <key>Minute</key> <integer>30</integer> </dict> <dict> <key>Weekday</key> <integer>5</integer> <key>Hour</key> <integer>16</integer> <key>Minute</key> <integer>45</integer> </dict> </array> </dict> </plist> 

Hinweis: Ich habe es mit einem hart codierten Benutzernamen in den Dateipfaden und der Systemvariablen $ USER versucht.


Ich habe die Berechtigungen für die Skripte geändert und die plist-Dateien wie folgt über das Terminal geladen:

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 

Wie viele vermuten, hat dies nicht funktioniert und wenn ich versuche, die geplanten Aufgaben manuell zu starten:

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

Nichts passiert.

Kann irgendjemand da draußen (mit mehr als einer <1-tägigen Erfahrung mit Apple-Script und launchd)? Bitte geben Sie an, wie Sie dies erreichen können.

1

0 Antworten auf die Frage