I’m running into an issue on Sonoma. Using the code below, the text version of the current date timestamp in the text file contains a ‘?’ character before the AM/PM - this does not happen on previous versions of MacOS. When reading it back in and turning it into a date again, it breaks due to the ? character, and reverts to midnight of the date given, not the correct timestamp.
Example: Thursday, October 5, 2023 at 1:45:57?AM
I’m assuming this is a bug in Sonoma, just not sure if it is related to the current date command or the write command?
on run
set theFile to ((path to desktop folder) as text) & "timestamp.txt"
set theExpiration to ((current date) + 12 * hours) as text
set theContents to theExpiration
my writeFile(theContents, theFile, false) -- text file contains an errant ? file before AM/PM
set theReadFile to (read (theFile as alias))
set theExpiration to date theReadFile -- Does not include the time on Sonoma
end run
on writeFile(this_data, target_file, append_data)
try
set the target_file to the target_file as text
tell application "Finder" to 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
close access the open_target_file
return true
on error theerr
try
tell application "Finder" to close access file target_file
end try
return false
end try
end writeFile