Launchd running an Applescript every two hours I have written a small applescript that I would like to run automatically every 2 hours. I have thus written the following launchd daemon (probably it is an agent): 

&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;Disabled&lt;/key&gt;
        &lt;false/&gt;
        &lt;key&gt;Label&lt;/key&gt;
        &lt;string&gt;com.zerowidth.launched.aspect&lt;/string&gt;
        &lt;key&gt;Program&lt;/key&gt;
        &lt;string&gt;/usr/bin/osascript&lt;/string&gt;
        &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
                &lt;string&gt;osascript&lt;/string 
                &lt;string&gt;/Users/***/my_script.scpt&lt;/string&gt;
        &lt;/array&gt;
        &lt;key&gt;StandardOutPath&lt;/key&gt;
        &lt;string&gt;/Users/***/file_log.log&lt;/string&gt;
        &lt;key&gt;RunAtLoad&lt;/key&gt;
        &lt;true/&gt;
        &lt;key&gt;ThrottleInterval&lt;/key&gt;
        &lt;integer&gt;7200&lt;/integer&gt;
        &lt;key&gt;KeepAlive&lt;/key&gt;
        &lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Then I have opened terminal and done 

launchctl load ~/Library/LaunchAgents/com.zerowidth.launched.aspect.plist 


It worked fine, but only once and not every two hours. Checking on Console I got the following messages (and many more actually):


  com.apple.xpc.launchd[1] (com.zerowidth.launched.aspect): This service
  is defined to be constantly running and is inherently inefficient.
  
  Dec 16 17:02:25 Air-of-myself-2 com.apple.xpc.launchd[1]
  (com.zerowidth.launched.aspect): Service only ran for 7 seconds.
  Pushing respawn out by 7193 seconds.


Can you help me in understanding what is going on please? How can I run the apple script every two hours? 

Thanks. 



EDIT. I add, following Robert's advice, the Python script and the Applescript. 

Here is Python script. It asks the console to run the LocateMe command and from this it obtains the latitude and longitude of the place where I am. Then calls an API to obtain sunset and sunrise time of this place. Finally a small function decides whether it is day (sunrise &lt; now 

output = os.popen('/Users/***/Desktop/LocateMe').read()
###I extract my coordinates 
coord = output[1:25]
lat = float(coord[1:12]) ###latitude
long = float(coord[13:25]) ### longitude

my_sunrise, my_sunset = get_ris_and_set(lat, long) ##this function calls an API that gives sunset and sunrise time in the position given by (lat,long)
my_sunset1 = my_sunset.time()
my_sunrise1 = my_sunrise.time()

result = str(is_day(now.time(), my_sunrise1, my_sunset1))
### compare the time now and returns true if it is day false otherwise    
with open('/Users/***/Desktop/log_file.txt', 'a') as f:
        print(result, file=f)
sys.exit()


Here is the Applescript: it runs the Python script above and reads the boolean value (if it is day or not). Then it checks if the dark mode on Mojave is on and it switches if needed. 

tell application id "com.apple.systemevents"
tell application "Terminal"
    do shell script "/usr/local/bin/python3 /Users/***/Desktop/python.py $@"
end tell

tell appearance preferences
    set value to do shell script "tail -n 1 /Users/***/Desktop/log_file.txt"
    if dark mode is true and value = "True" then
        set dark mode to false
    else if dark mode is false and value = "False" then
        set dark mode to true
    else
        return
    end if
end tell
end tell
Isn't StartInterval the key for running periodically? In your case, set to 7200 (seconds)?

https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html#//apple_ref/doc/uid/10000172i-SW7-SW7