Alternative to using temporary items?

This has been discussed in earlier threads, but I can’t find any solution. I have some scripts that write files to the folder for temporary items and then open those files in TextEdit. Ever since (I think) Catalina, those scripts only work if I grant them full disk access.

I’ve tried to trap the alert that macOS displays when my script tries to open the files, so that I can tell the user to grant FDA to the applet, but the try…on error…end try loop doesn’t catch the error; macOS displays the alert no matter what I do.

Is there a way to test whether a script has FDA, or is there an alternative to using the temporary items folder for this purpose?

Which applet do you mean?

I was about to post one such applet, but today the problem doesn’t occur, so I’ll have to experiment further.

You can test for full disk access with the line:

set hasFDA to (do shell script "cat ~/Library/Preferences/com.apple.TimeMachine.plist &> /dev/null; echo $?") is "0"

You can make a temporary folder with…

to makeTemporaryFolder()
	return do shell script "mktemp -d"
end makeTemporaryFolder

This returns the POSIX path to the folder.

2 Likes

Thank you for this - mktemp was entirely new to me and is very useful indeed!

1 Like