Mail import script failure after changing computer

Hi all,

I have successfully used a combination of AppleScript and Python to import email from Mail.app into DNTP for years now. I just changed to a new computer and restored everything from a disk clone, but what doesn’t get restored is the settings in the Privacy & Security system settings. The following snippet in my AppleScript returns empty lists now, even though I can prove from logging in my Python script that the files and folders are created in “theFolder”:

		tell application "System Events"
			set theImportFiles to POSIX path of every file of folder theFolder
			set theImportFolders to every folder of folder theFolder
		end tell

“theFolder” refers to “(POSIX path of (path to temporary items))” as seen by Mail.app, which translates to “/Users/jens/Library/Containers/com.apple.mail/Data/tmp/TemporaryItems/”. There is no error raised, I just get empty lists.

I believe the root cause is a missing security declaration that allows “Full Disk Access” for “System Events”, which my previous computer shows. But I can’t seem to add “System Events” in the list of applications for “Full Disk Access”, and the system is not presenting me with a dialog asking me to do so when the code hits that place.

Would anyone know how I can fix that apparent security entitlement issue?

Thanks!

I finally found where “System Events” resides (/System/Library/CoreServices/System Events) and was able to add it manually to the list of applications that have full disk access. My earlier attempts to use SpotLight to search for that application did not find it.

The solution is unsatisfactory - I really only want System Events to access Mail.app’s temporary folder - but it works. I suspect the better solution would be to add System Events to the Privacy & Security “Automations” and allow it to control Mail.app, but that list doesn’t allow manual additions.

That’s far from a “prove” :wink: All it might do is prove that your Python script did at some time generate files in the folder. It does not prove that these files are still there when you run your AppleScript code.

What does ls /Users/jens/Library/Containers/com.apple.mail/Data/tmp/TemporaryItems/ tell you immediately before you run your AS code? It is, I think, highly improbable that System Events tells you the folder is empty when it isn’t.

Improbable too. If that were the issue, you’d see an error message. And if granting full disk access to System Events were needed, I couldn’t run your code. But I can.

What’s your old and new OS, BTW?

Like I said, granting Full Disk Access to System Events fixed the issue. The OS was Sonoma 14.1.1 on both the old and new system.

You wrote that while I was still working on my post :wink: Thanks for locating the thing – I always though System Events to just be a framework, not an app. Learned something new now.

P.S.: Doing a simple “ls” on that temporary items folder yields “Operation not permitted”, both for my user account and with sudo.

My WAG would be that each process gets their own highly-filtered view onto that folder, which may not always throw an error, and it may not always cause the system to prompt for permissions to that folder.