'macOS python PDF service denied access in macOS Catalina

Since many years I have been using a Python script, to add a "virtual printer" to my macOS printing dialogue and print on a PDF stationery from any application.

The script is placed within ~/Library/PDF Services, took sys.argv[3] as an input file, merged the input file with a given PDF stationery and saved it in ~/Downloads.

I was happy until I updated to macOS Catalina and always got this message from Console:

Sandbox: Python(30225) System Policy: deny(1) file-read-data /Users/me/Documents/stationery.pdf

It seems that, due to the new permissions in macOS Catalina, the script cannot access the stationery file anymore. Python however has full hard disk access.

If I run the same script from the Terminal, everything works fine.

How can I grant the script access to the required document (/Users/me/Documents/stationery.pdf) when executed from withing the printing dialogue?



Solution 1:[1]

EDIT:

This problem seems to have been fixed in Monterey: python scripts will now correctly run as PDF Services.

(Of course, they're removing python, so you'll have to install your own. Swings and Roundabouts.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1