Friday, May 27, 2022

#26 2021-10-30 01:13:18 am

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

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

lotr wrote:

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



I did a timeout as suggested and it makes no difference.  I am getting a bit frustrated that I can not get this to work.  Scripts run fine when manually activated but not when trigged.  Is this a OS11 bug?  I do not know.

I also tested it with a application called Scheduler (https://www.macscheduler.net -- a versatile app by the way and free, how the developer does it I can not say, but lovely).

Has anybody any idea as to how to proceed?  I hope so.


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

Jim Barksdale - CEO Netscape

Offline

 

#27 2021-10-30 01:49:13 am

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

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

db123 wrote:

@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!



Thanks for this db123.  I am not a AS champion but think I can follow the thinking here.  I did not know that you could do this and how to do it.

I am back at the machine and will start to experiment today.  Hopefully I see something in the logs that helps.


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

Jim Barksdale - CEO Netscape

Offline

 

#28 2021-10-31 03:56:43 am

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

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

db123 wrote:

@SW108:


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!



Thank you I did not know how to get it to write to the log.  My log looks similar.  And you posting it helps me to see I did it right.  Thanks again.

it all looks a bit complex to me and I do understand some of it, the block at the end is in places a bit of a mystery to me, but I get the gist I think.  I am running a test now as I am back at the machine (same room).  It is running on an hourly bases and I hope it catches the problem.

Last edited by SW108 (2021-10-31 03:57:37 am)


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

Jim Barksdale - CEO Netscape

Offline

 

#29 2021-10-31 04:23:55 am

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

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

DB123.

you wirte at the start of your script

''

Applescript:

use framework "Foundation"
use scripting additions

is this only for the logging or is that useful to do anyway. 

I ask as have seen this in other scripts on the WWW. before, like this one:

Applescript:

use AppleScript version "2.5"
use framework "Foundation"
use framework "AppKit"
use scripting additions

Could this be part of my problem?  And if so what version of AppleScript should be used in OS11?  I see that Script Editor is now in version 11.  But can not find a AppleScript application like in the olden days.


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

Jim Barksdale - CEO Netscape

Offline

 

#30 2021-10-31 04:56:05 am

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

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

SW108 wrote:

is this only for the logging or is that useful to do anyway.

Yes, the Foundation framework is required for logging (AppleScriptObjC). It is not relevant to your code.

SW108 wrote:

Could this be part of my problem? And if so what version of AppleScript …

No. I don't think so. The specification is for a minimum version:

Applescript:


use AppleScript version "2.5"
get version of AppleScript
--> 2.7

2.7 is the AppleScript version of Big Sur.

Offline

 

#31 2021-10-31 04:58:02 am

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

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

db123 wrote:


2.7 is the AppleScript version of Big Sur.



Thanks.

FMI, how do you find out?  Where does it hide?


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

Jim Barksdale - CEO Netscape

Offline

 

#32 2021-10-31 01:15:12 pm

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

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

Skripteditor -> About Skripteditor

Offline

 

#33 2021-10-31 01:47:07 pm

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

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

db123 wrote:

Skripteditor -> About Skripteditor




aha so simple


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

Jim Barksdale - CEO Netscape

Offline

 

#34 2021-11-01 08:29:50 am

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

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

Thanks for this db123 and other answers.

The test finally did not work with the test script you suggested and so I have an error report.  And it does not help me.  All I see is that it stopped after checking the network and before or while Mail was firing up.

Are there further test steps one could add to see more?

Here it is:

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?

Could it be a security setting somewhere?


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

Jim Barksdale - CEO Netscape

Offline

 

#35 2021-11-01 02:22:16 pm

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

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

The error seems to occur when accessing the mail applicatiion.

SW108 wrote:

Any ideas as too how to proceed?

Change the script in the following section and create a log again:

Applescript:



set theBody to "Text"
set theSubject to "Text"
set theTarget to "<name@yahoo.com>"

my writeToLog("Mail-Script call test application")
tell application "TextEdit"
   get version
end tell

my writeToLog("Mail-Script call mail application")
tell application "Mail"
   my writeToLog("Mail-Script create new message")

This can be used to check if the problem is specific to the mail application, or if all access to other applications is a problem.

Last edited by db123 (2021-11-01 02:26:42 pm)

Offline

 

#36 2021-11-01 03:00:16 pm

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

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

db123 wrote:

The error seems to occur when accessing the mail applicatiion.

SW108 wrote:

Any ideas as too how to proceed?

Change the script in the following section and create a log again:

Applescript:



set theBody to "Text"
set theSubject to "Text"
set theTarget to "<name@yahoo.com>"

my writeToLog("Mail-Script call test application")
tell application "TextEdit"
   get version
end tell

my writeToLog("Mail-Script call mail application")
tell application "Mail"
   my writeToLog("Mail-Script create new message")

This can be used to check if the problem is specific to the mail application, or if all access to other applications is a problem.



Great.  Will give it a go tomorrow when back at the machine, and thanks!


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

Jim Barksdale - CEO Netscape

Offline

 

#37 2021-11-02 10:00:53 am

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

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

Hi db123.

I adjusted the script as you suggested and it now flips out on starting TextEdit.

here is the log.


2021-11-02 14:51:01.074 -------------------
2021-11-02 14:51:01.094 Mail-Script started
2021-11-02 14:51:01.111 Mail-Script network check started
2021-11-02 14:51:06.171 Mail-Script network check finished
2021-11-02 14:51:16.203 Mail-Script call test application TextEdit start
2021-11-02 14:51:16.223 Mail-Script call test application TextEdit end
2021-11-02 14:51:18.241 Mail-Script call test application Console start
2021-11-02 14:51:18.249 Mail-Script call test application Console end
2021-11-02 14:51:20.518 Mail-Script System Events
2021-11-02 14:51:20.531 Mail-Script ended
2021-11-02 15:51:01.372 -------------------
2021-11-02 15:51:01.392 Mail-Script started
2021-11-02 15:51:01.409 Mail-Script network check started
2021-11-02 15:51:06.485 Mail-Script network check finished
2021-11-02 15:51:16.512 Mail-Script call test application TextEdit start
2021-11-02 15:51:16.532 Mail-Script call test application TextEdit end
2021-11-02 15:51:18.548 Mail-Script call test application Console start
2021-11-02 15:51:18.558 Mail-Script call test application Console end
2021-11-02 15:51:20.884 Mail-Script System Events
2021-11-02 15:51:20.901 Mail-Script ended
2021-11-02 16:51:00.602 -------------------
2021-11-02 16:51:00.621 Mail-Script started
2021-11-02 16:51:00.637 Mail-Script network check started
2021-11-02 16:51:05.762 Mail-Script network check finished


as you see it ran twice and then failed in the same spot. 

Here is the script I used.

Applescript:


-- start logging

use framework "Foundation"
use scripting additions
--start log stuff
set logFileName to "MyScripts.log" -- log stuff change if you like

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@gmx.net>"

my writeToLog("Mail-Script call test application TextEdit start")
tell application "TextEdit"
   get version
   my writeToLog("Mail-Script call test application TextEdit end")
end tell

delay 2

my writeToLog("Mail-Script call test application Console start")
tell application "Console"
   get version
   my writeToLog("Mail-Script call test application Console end")
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

So strange it runs twice and then flips out.  All the other scripts do this, they run several times and next the fail.  Any idea?


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

Jim Barksdale - CEO Netscape

Offline

 

#38 2021-11-02 11:04:47 am

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

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

What is this???

Applescript:



display dialog "Finished checking - Network is up and running" buttons {"OK"} default button "OK" giving up after 6
delay 3

say "OK"

I have assumed so far that you have used the script posted by me. In this I had removed display dialog and say "OK" etc. because something like that (UI) has no place in an automatically executed script! That's what the log is for!

And the do shell script commands are also new (for me).

Applescript:


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'")

If the log is to make sense and you want to know up to which step the script runs, then you must also log every important step:

Applescript:


my writeToLog("Mail-Script do shell script theBody")
set theBody to ("MyScripts.log - ") & (do shell script "date '+%d-%m-%Y - time %H-%M-%S'")
my writeToLog("Mail-Script do shell script theSubject")
set theSubject to ("MyScripts.log - ") & (do shell script "date '+%d-%m-%Y - time %H-%M-%S'")
my writeToLog("Mail-Script do shell script end")

PS: Check if you have signed the applet for run locally. The selection is available when you export the script as applet.

Offline

 

#39 2021-11-02 02:16:46 pm

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

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

db123 wrote:


PS: Check if you have signed the applet for run locally. The selection is available when you export the script as applet.



first off, how do you do this?  I see no option to do so when I save the script as an applet.

I will tomorrow incorporate your suggestion.  Now away from the machine.

Last edited by SW108 (2021-11-02 02:17:55 pm)


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

Jim Barksdale - CEO Netscape

Offline

 

#40 2021-11-02 03:02:29 pm

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

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

I had written:

… when you export the script as applet.

Offline

 

#41 2021-11-03 01:53:56 am

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

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

db123 wrote:

I had written:

… when you export the script as applet.




I know so I have the script, do a save-as, select Application, and next?  Where is this option?  How to activate?

here a pic of the window:  https://ibb.co/GvHSKYv


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

Jim Barksdale - CEO Netscape

Offline

 

#42 2021-11-03 08:51:26 am

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

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

Use "Export" instead of "Save as".

Offline

 

#43 2021-11-03 09:31:23 am

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

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

db123 wrote:

Use "Export" instead of "Save as".



I did not know that.  Thanks.

I have implemented it and am running the following test script.

Applescript:


use framework "Foundation"
use scripting additions

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

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

my writeToLog("Mail-Script call test email info")
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 "<me@email.com>"
my writeToLog("Mail-Script call test application email info end")

my writeToLog("Mail-Script call test application TextEdit start")
tell application "TextEdit"
   get version
   my writeToLog("Mail-Script call test application TextEdit end")
end tell

my writeToLog("Mail-Script delay start")
delay 2

my writeToLog("Mail-Script delay end")

my writeToLog("System Event start")
tell application "System Events"
   set visible of (every process whose visible is true) to false
   set visible of process "Finder" to true
   my writeToLog("System Events end") -- log stuff
end tell



-- more log stuff


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

For my information, is this last bit of code needed?  And if so what does it do?

Applescript:

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

Last edited by SW108 (2021-11-04 08:34:14 am)


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

Jim Barksdale - CEO Netscape

Offline

 

#44 2021-11-04 12:29:27 am

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

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

More info.  I ran the above script automatically every hour for 12 hours.  no errors.  So I think I can assume it is working since I did get errors before after 2 or 3 runs.

What would you suggest is the next step?


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

Jim Barksdale - CEO Netscape

Offline

 

#45 2021-11-04 07:23:56 am

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

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

Add your email code again like this:

Applescript:


use framework "Foundation"
use scripting additions

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

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

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

my writeToLog("Mail-Script call test email info")
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 "<target@yahoo.com>"
my writeToLog("Mail-Script call test application email info end")

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@yahoo.com>"
   end tell
   my writeToLog("Mail-Script send message")
   send newMessage
end tell

my writeToLog("System Event start")
tell application "System Events"
   set visible of (every process whose visible is true) to false
   set visible of process "Finder" to true
   my writeToLog("System Events end") -- log stuff
end tell

my writeToLog("Mail-Script ended")

-- more log stuff

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

Don't forget to sign the applet for local run and if everything works, then finally remove the log entries.

Last edited by db123 (2021-11-05 05:03:02 am)

Offline

 

#46 2021-11-05 04:50:34 am

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

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

DB123
did you see my personal message?

Last edited by SW108 (2021-11-05 07:30:05 am)


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

Jim Barksdale - CEO Netscape

Offline

 

#47 2021-11-06 06:20:28 am

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

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

SW108 wrote:

DB123
did you see my personal message?



Thanks for fixing.

I am now testing emails incorporating your suggestions.  so far so good, but only tested 2.


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

Jim Barksdale - CEO Netscape

Offline

 

#48 2021-11-08 10:47:00 am

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

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

it all seems to work since one day.  Thanks again. 

I have some Automator workflows, can one sign those too?  On my machine that option is greyed out.


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

Jim Barksdale - CEO Netscape

Offline

 

#49 2021-11-08 11:02:38 am

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

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

Automator workflows should work without signature or are signed automatically.

Offline

 

#50 2021-11-08 11:33:49 am

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

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

db123 wrote:

Automator workflows should work without signature or are signed automatically.


I did not know that they sign automatically.  Thanks.


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)