"Read File" permission errors in temporary folder on Catalina

So my latest Catalina script conversion headache…

I’m trying to read the contents of a file in the temporary items folder, but keep getting “File Permission Error”

#set qbAuthFile to (path to desktop folder as text) & "qb.dat" -- this works fine
set qbAuthFile to (path to temporary items folder as text) & "qb.dat" -- this gives permissions errors in Catalina
tell application "Finder" to set theXmlContents to (read file qbAuthFile)

The same file on the desktop reads fine, it is only when I put it in the temp folder that it has issues. Never been an issue prior to Catalina

Is there a change to the code I need, or is there something fundamentally different about the temporary items folder in Catalina that will prevent its use in this way? I often use the temp folder to pass info from one script to the next, etc

Your code works here, however it generates an error because you’re telling the Finder to read. But AS then automatically redirects the read command.

The read/write related commands should never be directed to an app.

Got the same error with this:

set qbAuthFile to (path to temporary items folder as text) & "qb.dat"
set theXmlContents to (read file qbAuthFile)

I’m not sure what to suggest. That code works fine here (10.15.4).

OK thanks. Maybe it’s a system issue instead of an Applescript one. I appreciate it!

Really odd. I tried this on a different machine, and got the same error. Brand new text file, created on the desktop, copied into the temp folder. I was hoping it was something on my other machine. Both on 10.15.4

Oh, well.

Try writing a file there (using AS) instead.

set target_file to (path to temporary items folder as string) & "qb.dat"
my writeFile("Hello World", target_file, false)
set qbAuthFile to (path to temporary items folder as text) & "qb.dat" 
set theXmlContents to (read file qbAuthFile)

This worked fine when the same script wrote to the temp folder. But when I tried to read a file that was created by a different script (or maybe the same script in a previous run), then it gave the permission error in the temporary folder. If the first script wrote the file to the desktop, all was fine.

I think I may have figured it out though, at least partially. I had not given my script, or for that matter Script Debugger, “full Disk Access” in the dreaded Catalina ‘Security & Privacy’ System Preferences. I know my main script had asked for access to the desktop folder at one point, but I guess it doesn’t ask for permission to the temp folder? Either way, when I gave Script debugger full disk access, it read the file fine with the code above.

On a side note, in this I also discovered that a trick I used to use a lot to see if a file existed will have to change. I often used:

set theVariable to (path to desktop folder as text) & "myfile.txt"
	theVariable as alias
	--it's there
on error
	-- it's not there
end try

If the file wasn’t there the error would say ‘Macintosh HD:Users:sdye:Desktop:myfile.txt’ wasn’t found but in Catalina it gives the error Can’t make ‘Macintosh HD:Users:sdye:Desktop:myfile.txt’ into type alias

While that essentially is saying the same thing, it’s damn annoying since I expected the other verbiage and looked for it in my scripts at times. Somewhere in-between these two issues seems to be where the bug in my larger code lies…