Trouble with Apple Script permission

I encountered an error:
error “Finder got an error: The operation can’t be completed because you don’t have the necessary permission.” number -5000

Here is the AppleScript code:

with timeout of 18000 seconds
	-- Get the current user's home folder
	set homePath to (path to home folder) as string
	
	-- Create file paths
	set sourceFavorites to homePath & "Downloads:com.apple.LSSharedFileList.FavoriteItems.sfl3"
	set sourceVolumes to homePath & "Downloads:com.apple.LSSharedFileList.FavoriteVolumes.sfl3"
	set destinationFolder to homePath & "Library:Application Support:com.apple.sharedfilelist"
	
	-- Move the file with Favorites checkboxes to Finder Settings
	tell application "Finder"
		set sourceFile to alias sourceFavorites
		set destination to folder destinationFolder
		move sourceFile to destination with replacing
	end tell
	
	-- Move the file with Locations checkboxes to Finder Settings
	tell application "Finder"
		set sourceFile to alias sourceVolumes
		set destination to folder destinationFolder
		move sourceFile to destination with replacing
	end tell
	
	-- Shows disks and devices on desktop
	tell application "Finder"
		activate
		set desktop shows connected servers of Finder preferences to true
		set desktop shows removable media of Finder preferences to true
		set desktop shows external hard disks of Finder preferences to true
		set desktop shows hard disks of Finder preferences to true
	end tell
end timeout

The problem is related to moving the files
com.apple.LSSharedFileList.FavoriteItems and com.apple.LSSharedFileList.FavoriteVolumes.
These files contain the settings for Bookmark and Locations in Sidebar in Finder Settings.

Usage scenario:
We need to prepare new Apple devices for work, and one of the requirements is to configure specific Finder Settings.
Of course, it’s always possible to configure everything manually, but I’m writing this AppleScript to avoid manual work.

A few additional notes:
When running the script, macOS asks for permission; I enter the password and click OK.

On macOS Sequoia 15.2, everything works fine.

On version 15.5, it turns out I don’t have enough permissions anymore.

I also tried exporting the AppleScript as an App, but the result is the same.

The directory Library:Application Support:com.apple.sharedfilelist is protected,
but in Finder GUI I can still enter this folder and copy the files there manually.

Disabling SIP (System Integrity Protection) is not an option—
on new devices this will only cause more trouble, plus it’s unsafe.

Even using sudo in the shell does not give me access to this folder—it returns Operation not permitted.

Are there any solutions to this kind of problem?

Hi @Dznww5. Welcome to MacScripter.

Your script works perfectly well on my own 15.5 system. But I’ve only been able to test it by copying the existing files from the destination folder to my Downloads folder and then using the script to move them back. A guess in the dark would be that the files in your Downloads folder have been downloaded and still have quarantine attributes set. If this is the case, you could try inserting lines to remove these attributes before trying to move the files, eg.:

-- Move the file with Favorites checkboxes to Finder Settings
tell application "Finder"
	set sourceFile to alias sourceFavorites
	-- Remove the quarantine attribute. (This will error if the attribute isn't actually set!)
	do shell script ("xattr -d com.apple.quarantine " & (quoted form of POSIX path of sourceFile))
	set destination to folder destinationFolder
	move sourceFile to destination with replacing
end tell

Thanks for your answer
i test your solution later and back with feedback
also check attributes