Save from Word to rtf without "grant access" dialog?

This should be easy, I think, but nothing I’ve found has solved it. I have a script that opens a DOC or DOCX file and saves to an RTF file (which is then moved somewhere else and renamed, so the RTF file can go anywhere). I can’t figure out how to prevent the dreaded “grant access” dialog box, even though I think I’m creating a file object that should be able to solve it.

A StackOverflow post led me to try this (cnvFile is a file chosen by the user or dropped on the script):


				try
					set posixCnvFile to (POSIX path of cnvFile) as POSIX file
					tell application "Finder"
						set rtfPath to ((container of cnvFile) as text) & ("temp-temp-temp.rtf" as text)
					end tell
				on error err
					display dialog "DEBUG: " & err
				end try
				
				try
					tell application id "com.microsoft.Word"
						set isRun to running
						try
							activate
							set inFile1 to open file name posixCnvFile
							alias rtfPath
							save as inFile1 file name rtfPath file format format rtf with overwrite
							close inFile1 saving no
						on error err
							display dialog "debug Word " & err
						end try
						if not isRun then quit
					end tell
				end try
				

But that still produces the grant access dialog. Can anyone tell me the (probably obvious) solution?

With a little more searching, I found this solution (I imagine something simpler is out there):



try
	set posixCnvFile to (POSIX path of cnvFile) as POSIX file
	tell application "Finder"
		set rtfPath to ((container of cnvFile) as text) & ("temp-temp-temp.rtf" as text)
	end tell
on error err
	display dialog "Debug set rtfPath: " & err
end try
				
set rtfPath to my createEmptyFile(rtfPath)
				
try
	tell application id "com.microsoft.Word"
		set isRun to running
		try
			launch
			set inFile1 to open file name posixCnvFile
			save as inFile1 file name rtfPath file format format rtf with overwrite
		on error err
			display dialog "debug Word1 " & err
		end try
		try
			close active document
		on error err
			display dialog "debug Word2 " & err
		end try
		if not isRun then quit
		end tell
end try

on createEmptyFile(f)
	try
		do shell script "touch " & quoted form of POSIX path of f -- create file (this command does nothing when the RTF file exists)
	on error err
		display dialog "debug createEmptyFile: " & return & err
	end try
	return (POSIX path of f) as POSIX file
end createEmptyFile

Apologies for kludgy code and inconsistent variable naming; I simply lifted these from other sources.