Word Save As PDF Droplet sandbox(?) problem?

I’ve created a script to save dragged Word documents as PDFs (with lots of thanks to people/code from here).

It works perfectly on my test/development system, but when I move it to its production system, it fails currently. It was working prior to a system restart last week. Just before the restart Word was updated to 16.33. However, Word on the test system is also 16.33.

Both machines are running Mojave 10.14.6 with all current Apple updates installed.

I’ve compared System Preferences-Security & Privacy-Privacy-Automation, Accessibility, Full Disk Access between the two systems and the settings appear to be the same.

Interestingly, on the test system, once Word prompts for access to the destination folder, I don’t see that request again. On the production system, I am constantly prompted for access to the destination folder. I think this is a clue to the failure, but I don’t know where to look or how to fix it.

Here’s the code:

on open fillist
	set bs to "/"
	set d to "-"
	tell application "Finder"
		set defLoc to container of (item 1 of fillist) as alias
	end tell
	set destn to choose folder with prompt "You are converting Word files by copying them to PDF files." & return & "Select a location to save converted files." default location defLoc
	repeat with lvar in fillist
		tell application "Finder"
			set thename to name of lvar
			set filex to name extension of lvar
			set l to length of filex
		end tell
		set nuname to text 1 thru text item -(l + 1) of thename
		if "/" is in nuname then
			set oldDelims to AppleScript's text item delimiters
			set AppleScript's text item delimiters to bs
			set txtLst to every text item of nuname as list
			set AppleScript's text item delimiters to d
			set nuname to txtLst as string
			set AppleScript's text item delimiters to oldDelims
		end if
		set filname to (destn as string) & nuname & "pdf"
		--close access (open for access filname)
		
		tell application "Microsoft Word"
			launch
			open lvar
			save as active document file name filname file format format PDF
			close window 1 saving no
		end tell
	end repeat
end open

I’ve commented out the close access line as that was generating additional security request prompts on the test system and the script was working fine without it.

I tried to search here and the rest of the web for a solution, but haven’t found anything that either seems to work or is relevant.

Thanks for helping me figure this one out.

Cheers,
Jon

Model: iMac
Browser: Safari 605.1.15
Operating System: macOS 10.14

The dictionary of Standard Additions states:

open for access v : Open a disk file for the read and write commands
open for access file : the file or alias to open for access. If the file does not exist, a new file is created.
[write permission boolean] : whether to allow writing to the file.
→ integer : a file reference number; use for ‘read’, ‘write’, and ‘close access’

If I read well your code, your attempt to call this function doesn’t match its requirements.
The correct syntax may be :

close access (open for access file filname)
or
close access (open for access filname as «class furl»)

Always if I read well, the instruction
open lvar
is trying to open an item of class alias.
Are you sure that it’s what Word requires ?
A search on the web let me think that it want a unicode object.
My memory tell me that there was a recent exchange about that.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 28 janvier 2020 19:51:49

Yvan,

Thanks for your reply.

I should have been more specific with more detail. The failure on the production system occurs when trying to perform the save as PDF step. The document opens fine in Word, but I receive the Grant Access dialog from Word to select the folder in which to save the PDF, select the folder, then nothing happens-no PDF is created and the Word document is still on screen.

On my test system, once I’ve granted Word access to the destination folder (e.g. Desktop) on the initial execution of the script, I’m not prompted again, even for subsequent runs.

I’ve tried to read up on sandbox info as it would seem to be the most relevant, but most of what I’ve found has been resolved by Microsoft releasing a new version of Word which seems to fix the problem.

Thanks.

Cheers,
Jon

Have you tried to reactivate the instruction
close access (open for access filname as «class furl») (I use one of the correct syntax).

If my memory is right, it was required to create the PDF file before Word try to export in it.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 28 janvier 2020 21:13:16

I encountered a similar problem, but using my applets (custom applications) instead of Word.

Try to remove the permissions (old permissions belonging to the previous version of Word) for full disk access from the list. Then try to activate the permissions to full disk access again. On the production system.

Try adding this code where it will be run first:

set sd to path to startup disk
tell application id "com.microsoft.Word" -- Microsoft Word
	try
		close sd -- will error
	end try
end tell

That should clear any sandbox restrictions.

Shane,

This did the trick!

Thanks so much for the help.

Cheers,
Jon

This code stop working after updating to macOS 12.6.2 and using Microsoft Office 16.69.

Hi, if you have any update on this please let me know.