Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Change Agent

macrumors regular
Original poster
Oct 24, 2018
165
12
I have several events that get triggered by an Application called “Scheduler”. However sometimes I get massages that they time out. Below is one that times out on me. It is saved as an application. And in the Security Panel all preferences are set properly as it runs fine if I manually trigger it.

The first bit checks if we have a network, I added the spoken text etc. to hear if it is working since it is a server that runs the application. (Mac Mini OS 11.6.1)


-- check if network is up

set networkUp to false

repeat until networkUp is true

try

do shell script
"ping -o -t 5 www.google.com"

set networkUp to true

on error

beep

delay
0.5

say "Couldn't connect, no network"

beep

delay
1

beep

delay
5 -- something went wrong, so try again in 5 seconds

end try

end
repeat

beep

delay
0.5

say "Connected"

-- end

set myDateString to (weekday of (current date) as text) & " " & ((day of (current date)) as text) & " " & ((month of (current date)) as text) & " " & ((year of (current date)) as text) & (" - text") --change me

set theSubject to myDateString

set RN to random number from 1 to 6

set theBody to item RN of {"Message 1,



", "Message 2,



", "Message 3,



", "Message 4,



", "Message 5,



", "Message 6,



"}



set theTarget to "x@y.com"

tell application "Mail"

set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody}

tell newMessage

make new to recipient at end of to recipients with properties {address:theTarget}

set sender to "Test <1@2.com>"

end tell

delay
10

send newMessage

end tell


anybody has an idea as to how to fix this? Or what could be wrong?
 

Attachments

  • Screenshot 2021-10-17 at 08.34.21.png
    Screenshot 2021-10-17 at 08.34.21.png
    56 KB · Views: 272
This error can happen when an event takes an unusually long time to complete. If an event takes longer than two minutes, the Apple Event Manager reports a time-out error. To prolong the amount of time AppleScript waits for a response: Use the "with timeout" statement. Info: AppleScript Language Guide
 
This has a lot of similarities with your Calendar.app not running Apple Script Applications at time (OS11) post. Different error but the code looks similar. Added bonus is an application called “Scheduler”. Did you make this "Scheduler" application? My suggestion is to include log entries in the script/app to find the error that's causing the AppleEvent timed out error. That advice was also given here. What's up with al the delay statements?
 
Thanks.

https://www.macscheduler.net. It works a dream and is very flexible. Free application and it works good so far except the errors I get now. But those are Apple script errors.

I am now testing with a timeout in the script to see if this solves the problem.

I will add the above suggested log info as soon as I am back again.
 
This error can happen when an event takes an unusually long time to complete. If an event takes longer than two minutes, the Apple Event Manager reports a time-out error. To prolong the amount of time AppleScript waits for a response: Use the "with timeout" statement. Info: AppleScript Language Guide

Ok I did wrap it in a timeout (3600) and this does nothing. so somewhere it still bugs-out on me. Any suggestions anybody?
 
The script has been tweaked to include error messages to the log and looks like this now.

use framework "Foundation" use scripting additions -- start logging set logFileName to "MyScripts.log" -- log name my writeToLog("-------------------") --log stuff my writeToLog("Mail-Script started") --log stuff -- check if network is up repeat try my writeToLog("Mail-Script network check started") --log stuff set pingRequest to do shell script "/sbin/ping -c6 sslout.df.eu" if pingRequest contains "0% packet loss" then -- This will run the ping until there's no packet loss. my writeToLog("Mail-Script network check finished") --log stuff exit repeat beep else error "Packets lost" delay 10 error "Packets lost" end if on error errMsg number errNum -- log stuff my writeToLog("Mail-Script network check error: " & errMsg) -- log stuff delay 10 end try end repeat display dialog "Finished checking - Network is up and running" buttons {"OK"} default button "OK" giving up after 6 delay 3 say "OK" -- end set theBody to ("MyScripts.log - ") & (do shell script "date '+%d-%m-%Y - time %H-%M-%S'") set theSubject to ("MyScripts.log - ") & (do shell script "date '+%d-%m-%Y - time %H-%M-%S'") set theTarget to "<name@email.com>" tell application "Mail" my writeToLog("Mail-Script create new message") -- log stuff set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody} tell newMessage my writeToLog("Mail-Script add message recipient") -- log stuff make new to recipient at end of to recipients with properties {address:theTarget} set sender to "<sender@email.com>" end tell my writeToLog("Mail-Script send message") -- log stuff send newMessage end tell delay 2 tell application "System Events" set visible of (every process whose visible is true) to false set visible of process "Finder" to true my writeToLog("Mail-Script System Events") -- log stuff end tell -- more log stuff my writeToLog("Mail-Script ended") on writeToLog(newEntry) -- log stuff set logFile to (POSIX path of (home directory of (system info))) & "/Library/Logs/" & my logFileName set now to current application's class "NSDate"'s |date|() set df to current application's NSDateFormatter's new() df's setDateFormat:"YYYY-MM-dd HH:mm:ss.SSS" set txt to ((df's stringFromDate:(now)) as text) & " " & newEntry & return & linefeed set oFullPath to (current application's NSString's stringWithString:logFile)'s stringByStandardizingPath set {blnExists, intFolder} to (current application's NSFileManager's defaultManager()'s fileExistsAtPath:oFullPath isDirectory:(reference)) if blnExists then set oData to (current application's NSString's stringWithString:txt)'s dataUsingEncoding:(current application's NSUTF8StringEncoding) set h to current application's NSFileHandle's fileHandleForWritingAtPath:oFullPath h's seekToEndOfFile h's writeData:oData h's closeFile() else (current application's NSString's stringWithString:txt)'s writeToFile:(stringByStandardizingPath of oFullPath) atomically:true encoding:(current application's NSUTF8StringEncoding) |error|:(missing value) end if end writeToLog -- end log stuff



Here is the report:

2021-10-31 20:48:59.060 -------------------
2021-10-31 20:48:59.083 Mail-Script started
2021-10-31 20:48:59.100 Mail-Script network check started
2021-10-31 20:49:04.186 Mail-Script network check finished
2021-10-31 20:49:14.266 Mail-Script create new message
2021-10-31 20:49:14.583 Mail-Script add message recipient
2021-10-31 20:49:14.644 Mail-Script send message
2021-10-31 20:49:17.004 Mail-Script System Events
2021-10-31 20:49:17.016 Mail-Script ended

2021-11-01 13:30:00.801 -------------------
2021-11-01 13:30:00.944 Mail-Script started
2021-11-01 13:30:00.960 Mail-Script network check started
2021-11-01 13:30:06.039 Mail-Script network check finished

the first one is a working one the next one is a hung one with the box popping up "AppleEvent timed out".

Any ideas as too how to proceed? It seems to hang before Mail gets called.

Could it be a security setting somewhere?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.