Issue opening files from list after updating to macOS 12.6

I have a script that builds a list of files and then opens those files. It’s worked fine for years but after updating from macOS12.1 to macOS12.6 it’s stopped working and I can’t figure out why. It will build the list of files successfully and open the first file but it does not open any additional files. The Replies do not report any errors and show each file being opened, but only the first file is actually opened.

Here is a simple version of the script.

tell application "Finder"
	set Afolder to "Volumes:EOB Scans" as alias
	set fl to every file in Afolder
	repeat with f in fl
		open f
		delay 5
	end repeat
end tell

Replies:
tell application “Finder”
get every file of alias “EOB Scans:”
→ {document file “SKM_658e22091906330.pdf” of disk “EOB Scans”, document file “SKM_658e22091908320.pdf” of disk “EOB Scans”, document file “SKM_658e22091908350.pdf” of disk “EOB Scans”, document file “SKM_658e22091908380.pdf” of disk “EOB Scans”}
open document file “SKM_658e22091906330.pdf” of disk “EOB Scans”
open document file “SKM_658e22091908320.pdf” of disk “EOB Scans”
open document file “SKM_658e22091908350.pdf” of disk “EOB Scans”
open document file “SKM_658e22091908380.pdf” of disk “EOB Scans”
end tell

Any help would be appreciated.

I’ve done some more testing on this. I changed my default PDF viewer back to Preview. Now when I run the script I get a macOS error about not having permission to open the file. I do have permission to open the file.

What’s really odd is that if I manually open and close the pdf it will then open as expected when I run the script. This works for every pdf that I open manually regardless of which PDF viewer is set as the default program.

This is a known issue that is discussed in the following thread, which includes a number of possible workarounds:

https://macscripter.net/viewtopic.php?pid=210109

The following is a possible implementation of Stefan’s suggestion:

tell application "Finder"
	set Afolder to (path to desktop)
	set fl to every file in Afolder as alias list
	repeat with aFile in fl
		set contents of aFile to URL of aFile
	end repeat
end tell

repeat with f in fl
	open location f
	delay 5
end repeat