I'm trying to get a simple AppleScript to run from a rule in Mail.app under Catalina. The script is very basic:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
using terms from application "Mail"
on perform mail action with messages messageList in mailboxes mbox for rule aRule
repeat with theMessage in theMessages
set thisSender to (sender of theMessage as string)
my WriteLog("Recieved email from " & thisSender)
end repeat
end perform mail action with messages
end using terms from
-- the code, from here on, has been tested and runs from Script Debugger or Script Editor
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof as «class utf8»
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
on WriteLog(the_text)
set this_file to (((path to desktop folder) as text) & "log.txt")
my write_to_file(the_text, this_file, true)
end WriteLog
I have added the following rule to Mail.app:
I have also enabled full disk access for Mail.app:
The rule runs - the messages are moved to the filing folder - but the log file is not updated.
What else should I be looking at, to try to solve this issue?