Wednesday, December 8, 2021

#1 2021-10-18 01:02:20 am

SW108
Member
Registered: 2021-10-17
Posts: 36

Scripts saved as applications do not run if triggered by Calendar App.

Scripts saved as applications do not run if triggered by Calendar Application that is part of OS11

I have several scripts that send emails at different points of the day.  They get triggered by alarms in the Mac OS 11.6 Calendar application (its Version is 11.0 (2811.5.1)).

The problem is that I get errors that the script times out (-1712). (https://postimg.cc/sQNv0g2S)  Now if I run it directly by clicking the application it runs fine, all the time.  Every time I get the error, I run it manually (double click application) to check and it works. 

And next time it should be triggered by Calendar it times out again.  Now I have this problem with several scripts that should run.

One thought I had was that it maybe that the computer was asleep (it is a Mac Mini that is a blind server) and did not get the network connection up in time for sending the mail.  That is why I put the network check in front of it.  The address it pings is the mail server of my ISP.  Just to make sure this on is not down either.

Any idea as to how to solve this?

Thanks.


Applescript:

-- check if network is up

repeat
   try
       set pingRequest to do shell script "/sbin/ping -c6 sslout.df.eu"
       if pingRequest contains "0% packet loss" then exit repeat -- This will run the ping until there's no packet loss.
   on error
       beep
       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 "Text"
set theSubject to "Text"
set theTarget to "<name@yahoo.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 "<sender@fyahoo.com>"
   end tell
   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
end tell

Model: Mac Mini
Browser: Safari 605.1.15
Operating System: Other


Smart is not how much you know, but how quickly you learn.

Jim Barksdale - CEO Netscape

Offline

 

#2 2021-10-18 06:18:37 pm

lotr
Member
Registered: 2011-08-22
Posts: 117
Website

Re: Scripts saved as applications do not run if triggered by Calendar App.

On one hand I'm not qualified to answer the question, but a search suggested something like using a timeout:
eg:

Applescript:

tell application “xxx”
activate
with timeout of 3600 seconds
— do something
end timeout
end tell

This will override Applescripts default timeout of 2 mins, giving it longer to finish executing that command. This is a plagiarised answer. big_smile

Last edited by lotr (2021-10-18 06:22:07 pm)


The shy can light the dull dark room rich with life when their eyes mirror their inner sunrise

Offline

 

#3 2021-10-18 11:02:05 pm

SW108
Member
Registered: 2021-10-17
Posts: 36

Re: Scripts saved as applications do not run if triggered by Calendar App.

MM, could work, worth a try, will give it a go with a test today.

PS like your signature.


Smart is not how much you know, but how quickly you learn.

Jim Barksdale - CEO Netscape

Offline

 

#4 2021-10-19 12:28:40 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2182

Re: Scripts saved as applications do not run if triggered by Calendar App.

Are you sure you add open file alarm successfully? I can't do it either manually.

I can set open file alarm only manually with choosing application. But after few seconds Calendar.app removes this file from event. I checked with event  Info


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#5 2021-10-19 01:49:25 am

SW108
Member
Registered: 2021-10-17
Posts: 36

Re: Scripts saved as applications do not run if triggered by Calendar App.

well I don't see it being removed as it still shows in the Calendar GUI window.  or how do you check?


Smart is not how much you know, but how quickly you learn.

Jim Barksdale - CEO Netscape

Offline

 

#6 2021-10-19 08:13:36 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2182

Re: Scripts saved as applications do not run if triggered by Calendar App.

Close event's Info window and open it again. When I do that, the Info window removes added open file alarm. That means: Calendar.app doesn't save it (removes it). As I know, the dictionary of Calendar.app states: "Starting with OS X 10.14, it is not possible to create new open file alarms or view URLs for existing open file alarms".

So, to have open file alarm on new OSX workaround is following: make your calendar with events & open file alarms on some old OSX, copy this calendar to new OSX. Because created on the old OSX open file alarms works on new OSX. You can't just modify them.

Last edited by KniazidisR (2021-10-19 08:21:50 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#7 2021-10-19 10:16:48 am

db123
Member
Registered: 2020-12-07
Posts: 56

Re: Scripts saved as applications do not run if triggered by Calendar App.

KniazidisR wrote:

"Starting with OS X 10.14, it is not possible to create new open file alarms or view URLs for existing open file alarms".

It is still or again possible to create an event with "Open file…" under Big Sur (just tested successfully). Also, the entry in the calendar is preserved again when changes are made. This was different in the meantime, but works again.

Edit: It also works under Catalina (10.15.7). You must always use: alarm -> Custom -> Open file and then change "Calendar" to "Other…" and select the file.

Last edited by db123 (2021-10-19 10:31:02 am)

Offline

 

#8 2021-10-19 10:46:09 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2182

Re: Scripts saved as applications do not run if triggered by Calendar App.

Yes, I am on Catalina, I can add file choosing "Other...", but the problem is Calendar.app doesn't retain this adding. If you understand what I talk about. I guess, the same is with Big Sur

Last edited by KniazidisR (2021-10-19 10:47:34 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#9 2021-10-19 10:58:50 am

db123
Member
Registered: 2020-12-07
Posts: 56

Re: Scripts saved as applications do not run if triggered by Calendar App.

I just tested it again several times. Created a calendar entry that opens an applet that displays a notification. I changed the appointment several times and always the notification was triggered. Also, the file name remains (when I go through "Custom…") or I can select a new file.

PS: The file was always in my user folder

I remember that it was different (as you described), but it works for me now under macOS 10.15.7 and 11.6 (German).

Offline

 

#10 2021-10-19 11:03:30 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2182

Re: Scripts saved as applications do not run if triggered by Calendar App.

How you trigger the open file alarm? You have opened Event Info window or it is triggered with closed Info window on the time of event?


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#11 2021-10-19 11:07:55 am

db123
Member
Registered: 2020-12-07
Posts: 56

Re: Scripts saved as applications do not run if triggered by Calendar App.

Here is the video: http://bunar.de/temp/Catalina-Event-FileOpen.mov
(You have to wait a few seconds until the system time is 19:17)

Last edited by db123 (2021-10-19 11:27:34 am)

Offline

 

#12 2021-10-19 12:47:43 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2182

Re: Scripts saved as applications do not run if triggered by Calendar App.

db123 wrote:

I remember that it was different (as you described), but it works for me now under macOS 10.15.7 and 11.6 (German).


It looks like a nightmare. I am currently on Catalina 10.15.7. I confirm that the application file is successfully added in exactly the way shown in the video. But after a few seconds it is removed by the Calendars application from the event...

Last edited by KniazidisR (2021-10-19 12:49:33 pm)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#13 2021-10-19 12:58:09 pm

db123
Member
Registered: 2020-12-07
Posts: 56

Re: Scripts saved as applications do not run if triggered by Calendar App.

Maybe it's an iCloud or otherwise synced calendar?
I have only used the Automator calendar for such events. It is now also in iCloud, but it works. 
Try using a local calendar.

Offline

 

#14 2021-10-20 02:47:41 am

SW108
Member
Registered: 2021-10-17
Posts: 36

Re: Scripts saved as applications do not run if triggered by Calendar App.

It looks like it could be that some times when it does not work the machine is asleep or in some sort of rest.  not sure if that is it, but my experimenting seems (emphases on seems) to point in that direction.

Could that be?  I would find it strange.


Smart is not how much you know, but how quickly you learn.

Jim Barksdale - CEO Netscape

Offline

 

#15 2021-10-20 08:09:50 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2182

Re: Scripts saved as applications do not run if triggered by Calendar App.

db123 wrote:


I have only used the Automator calendar for such events.


The problem is I don't understand what do you mean with "Automator calendar". I tested with local calendar and your method doesn't work on my Catalina 10.15.7. Calendar.app removes added open file alarm.

I admit that it works on Big Sur, I cannot verify. I wonder if there is in the Calendars's dictionary of Big Sure note like the one I mentioned above regarding open file alarm.

Last edited by KniazidisR (2021-10-20 08:19:39 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#16 2021-10-20 08:59:15 am

SW108
Member
Registered: 2021-10-17
Posts: 36

Re: Scripts saved as applications do not run if triggered by Calendar App.

Thanks.

"Automator calendar" means in Automator you can make an alarm that schedules in Calendar.  That does not solve the problem either, gives the same faulty result.


Smart is not how much you know, but how quickly you learn.

Jim Barksdale - CEO Netscape

Offline

 

#17 2021-10-20 09:00:58 am

db123
Member
Registered: 2020-12-07
Posts: 56

Re: Scripts saved as applications do not run if triggered by Calendar App.

@KniazidisR:

With "Automator Calendar" I mean the one that is used or created when creating an Automator Calendar Alarm workflow. In this case, the "Open file feature" is also used.

The video was created with Catalina 10.15.7.

Offline

 

#18 2021-10-20 11:33:41 am

db123
Member
Registered: 2020-12-07
Posts: 56

Re: Scripts saved as applications do not run if triggered by Calendar App.

@SW108:

Since you get an error message from the applet, I don't assume that it has anything to do with KniazidisR's problem (disappearing settings in the calendar). The script is started, it just fails.

I have tried this once with your script under Big Sur (11.6). Here are my results:

It is not necessary that the calendar app is started. It is also not started when the event is triggered.

The event is not fired when the Mac asleep. Instead, it is triggered when the Mac wakes up again.  Since the applet is not started in this case, there can be no error message and therefore I do not assume that this has anything to do with it.
Possibly this behaves differently when Power Nap is activated and then only parts wakes up (e.g. the TaskScheduler for the event - but not other resources), but I could not test that in the time. This would be pretty weird.


Otherwise, it has run without any problems for me so far.

I would recommend you to disable Power Nap once to be on the safe side and include log entries in the script to find the error:

Applescript:


use framework "Foundation"
use scripting additions

set logFileName to "MyScripts.log" -- change if you like

my writeToLog("-------------------")
my writeToLog("Mail-Script started")

repeat
   try
       my writeToLog("Mail-Script network check started")
       set pingRequest to do shell script "/sbin/ping -c6 sslout.df.eu"
       if pingRequest contains "0% packet loss" then
           my writeToLog("Mail-Script network check finished")
           exit repeat
       else
           error "Packets lost"
       end if
   on error errMsg number errNum
       my writeToLog("Mail-Script network check error: " & errMsg)
       delay 10
   end try
end repeat

set theBody to "Text"
set theSubject to "Text"
set theTarget to "<name@yahoo.com>"
tell application "Mail"
   my writeToLog("Mail-Script create new message")
   set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody}
   tell newMessage
       my writeToLog("Mail-Script add message recipient")
       make new to recipient at end of to recipients with properties {address:theTarget}
       set sender to "<sender@fyahoo.com>"
   end tell
   my writeToLog("Mail-Script send message")
   send newMessage
end tell

my writeToLog("Mail-Script ended")

on writeToLog(newEntry)
   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

You can find the log in the Console app under "Log Reports". For example, it looks like this:

2021-10-20 18:45:28.682 -------------------
2021-10-20 18:45:28.834 Mail-Script started
2021-10-20 18:45:28.967 Mail-Script network check started
2021-10-20 18:45:34.253 Mail-Script network check finished
2021-10-20 18:45:34.468 Mail-Script create new message
2021-10-20 18:45:35.731 Mail-Script add message recipient
2021-10-20 18:45:36.085 Mail-Script send message
2021-10-20 18:45:36.388 Mail-Script ended

You can add more log entries and maybe find out where the timeout occurs.

Good luck!

Offline

 

#19 2021-10-21 01:01:43 am

SW108
Member
Registered: 2021-10-17
Posts: 36

Re: Scripts saved as applications do not run if triggered by Calendar App.

Thanks, DB123

I am going to give it a go.  Presently I am on the road for a few days so will have time on Saturday PM to engage.  The MM is at home, and I am not at the moment. 

I did some other testing. I ran an application that is called Jigler.  This is keeping the Mac active as it 'moves' the mouse every x minutes.  This makes no difference to the problem using Calendar to fire the scripts.  I get the same errors. 

Since at an earlier point I figured the network part of the hardware does not become active (similar along the lines of your thoughts) I added the ping bit.  This did not help either. 

Next, I installed an application called ‘Schedular’.  I did an overnight test with this email and sending it every 5 minutes.  If I have Jigler running it sends a mail every 5 minutes, if not it does not send it.  So now suspicion is, it is not Calendar or the script, but that indeed some part of the Mac does not wake up. 

Now my scripting skill is pretty limited, but is there a way to script the Mac to be fully fit and awake on all levels?  I know you can script ‘sleep’.  Can you wake it with a script? 

As to Power Nap, it is off.  And Jigler would also stop it from kicking in.  Here is a pic of my ES Panel.  https://postimg.cc/njbk2fmJ

Hope somebody out there has the solution, and thanks again everybody for engaging.


Smart is not how much you know, but how quickly you learn.

Jim Barksdale - CEO Netscape

Offline

 

#20 2021-10-21 04:02:28 am

db123
Member
Registered: 2020-12-07
Posts: 56

Re: Scripts saved as applications do not run if triggered by Calendar App.

SW108 wrote:

Now my scripting skill is pretty limited, but is there a way to script the Mac to be fully fit and awake on all levels?

Look for "caffeinate". It's on board. I use the command e.g. when I copy many and large files via script. If you execute it without parameters in the terminal, it prevents the sleep until you terminate the command with Ctrl+C or close the window.
Not nice, but at least you can test if it's because of that.

Offline

 

#21 2021-10-21 05:11:04 am

SW108
Member
Registered: 2021-10-17
Posts: 36

Re: Scripts saved as applications do not run if triggered by Calendar App.

Thanks DB123.

Look for "caffeinate". It's on board. I use the command e.g. when I copy many and large files via script. If you execute it without parameters in the terminal, it prevents the sleep until you terminate the command with Ctrl+C or close the window.



I have found Amphetamine this morning and loaded that.  It is testing presently.  Do you know about it?  it seems to have loads of functions.

Or is caffeinate a shell command or the likes? 

Do you know how both compare?

If you execute it without parameters in the terminal, it prevents the sleep



Not sure what you mean here.  included it in the AppleScript to lounge it at the start of the script?

until you terminate the command with Ctrl+C or close the window.



Close what window?

Last edited by SW108 (2021-10-21 05:15:53 am)


Smart is not how much you know, but how quickly you learn.

Jim Barksdale - CEO Netscape

Offline

 

#22 2021-10-21 06:05:16 am

db123
Member
Registered: 2020-12-07
Posts: 56

Re: Scripts saved as applications do not run if triggered by Calendar App.

SW108 wrote:

I have found Amphetamine this morning and loaded that.  It is testing presently.  Do you know about it?

Yes, but for me an app for this function was too much, since it is already part of the system.

SW108 wrote:

Or is caffeinate a shell command or the likes?

Yes, "caffeinate" is a shell command. Just run it in the terminal.

SW108 wrote:

Close what window?

The terminal window.

SW108 wrote:

Not sure what you mean here.

Run this in the terminal:

caffeinate -h

and you get: "usage: caffeinate [-disu] [-t timeout] [-w Process ID] [command arguments...]". Without parameter it runs endlessly.

You can also start it with AppleScript:

Applescript:


   do shell script "caffeinate </dev/null &>/dev/null &"

but then you can only stop it via the Activity Monitor. But maybe that would be a way to start it at system startup.

--- Edit ---
Of course, it also works with a Stay Open applet. Whether it makes sense is another question.

Applescript:


use scripting additions
property pid : missing value

on run
   set my pid to do shell script "caffeinate </dev/null &>/dev/null & echo $!"
end run

on quit
   do shell script "kill " & my pid
   continue quit
end quit

The interesting thing about the caffeinate command is that you can use it to prevent the mac asleep while another command or script is running.
------------

PS: The "</dev/null &>/dev/null &" part prevents the script from blocking at this point.

Last edited by db123 (2021-10-21 07:42:14 am)

Offline

 

#23 2021-10-27 12:44:36 am

SW108
Member
Registered: 2021-10-17
Posts: 36

Re: Scripts saved as applications do not run if triggered by Calendar App.

OK here i am again.

Powernap is disabled.  Makes no difference.

I will test today and see if i see anything in the log.


Smart is not how much you know, but how quickly you learn.

Jim Barksdale - CEO Netscape

Offline

 

#24 2021-10-27 09:35:16 am

SW108
Member
Registered: 2021-10-17
Posts: 36

Re: Scripts saved as applications do not run if triggered by Calendar App.

I am now also talking to Apple.  Was relutant to do this as it is always a matter of having hours of phone time.  Today I needed to be connected 4 times to different people but got one who seemed knowledgeable to than lose the connection.  but he emailed a possible solution we are going to try. Will keep you informed.


Smart is not how much you know, but how quickly you learn.

Jim Barksdale - CEO Netscape

Offline

 

#25 2021-10-30 01:06:22 am

SW108
Member
Registered: 2021-10-17
Posts: 36

Re: Scripts saved as applications do not run if triggered by Calendar App.

Apple said they send mail with suggestions, nothing came, need to phone again.


Smart is not how much you know, but how quickly you learn.

Jim Barksdale - CEO Netscape

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)