(1) I added some instructions at the very beginning to be sure that the required folder was available.
(2) As the datas written in the file are a list, the read instruction must read the file as list. The required coercion was disabled.
(3) The instruction supposed to display the read datas was asking display dialog to display a list which it cant't do.
So I added my old handler “recolle“ to convert the list into a text object.
Honestly I must add that I was surprised to see that the handler coerced the date values into text object with no explicit code.
My first thought was to use : my recolle({""} & temp, linefeed) to be sure that the first item of the list was a string.
Here is the code which I was able to run with no problem.
----------------------------------
property folderName : "Mail
Manager Folder"
property mailManagerDesktopFolderPath : ((path to desktop as text) & folderName & ":")
#property testFile : “.File Mail Size" as text
property testFile : "Store The Version IP.dat" as text
set p2d to path to desktop
tell application "System Events"
if not (exists folder mailManagerDesktopFolderPath) then make new folder at end of p2d with properties {name:folderName}
end tell
try
say 1
set p to 1
set temp to my readFile2(my testFile)
say 2
set p to 2
# You can't get display dialog to display your set of datas.
-- tell application "System Events" to display dialog temp as list # DISPLAY DIALOG CAN'T TREAT A LIST
-- tell application "System Events" to display dialog (my recolle({""} & temp, linefeed)) # FIRST ATTEMPT
tell application "System Events" to display dialog (my recolle(temp, linefeed)) # LAST VERSION
set p to 3
if (count of temp) = 6 then
say "found"
set p to 4
set StartDateOne to item 1 of temp as date
set p to 5
set tempMailCount to (item 5 of temp) + 1
set p to 6
set overallMailCount to (item 3 of temp) + 1
try
set p to 7
my writeFile8(my testFile, {StartDateOne, (current date) as date, overallMailCount, 0, tempMailCount, 0})
set p to 8
end try
else
say 10
set p to 9
my writeFile8((my testFile), {(current date) as date, (current date) as date, 0, 0, 1, 0})
say "wrote to"
end if
on error errmsg
tell application "System Events" to display dialog errmsg & " p = " & p
end try
on readFile2(theFileName)
try
set p to 10
set TheFileNameTemp to ((my mailManagerDesktopFolderPath) & theFileName)
set wholeList to read file TheFileNameTemp as list # EDITED
set p to 12
return wholeList
on error errmsg
say "error 1"
tell application "System Events" to display dialog "readFile2 p = " & p & " " & errmsg
return ""
end try
end readFile2
on writeFile8(theFileName, TheWriteItem)
try
say 100
set p to 13
set fRef to open for access file theFileName with write permission
set fRef to open for access file ((my mailManagerDesktopFolderPath) & theFileName) with write permission
set p to 14
say 101
set eof fRef to 0
set p to 15
say 102
write TheWriteItem to fRef -- < WORKS, BUT DOESN’T WRITE??????
say 103
on error errmsg
say "error 2"
tell application "System Events" to display dialog "WriteFile8 p = " & p & " " & errmsg
end try
try
close access fRef
end try
end writeFile8
on recolle(l, d) # ADDED Handler
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
----------------------------------