I am getting an 'Operation not permitted' when running Python file with AppleScript
I created a Service that writes a selected word to an Excel file. Running the .py file from PyCharm or Terminal works fine, but whenever I try to execute it with AppleScript I get a PermissionError. Why is this?
AppleScript
on run {input, parameters}
display dialog (input as text)
set venvPath to "/Users/ben/PycharmProjects/Excel_writer/venv/bin/python3.8"
set pyScript to "/Users/ben/PycharmProjects/Excel_writer/writer.py"
do shell script venvPath & " " & pyScript & " " & input
return input
end run
The action “Run AppleScript” encountered an error: “Traceback (most recent call last):
File "/Users/ben/PycharmProjects/Excel_writer/writer.py", line 26, in <module>
insert_to_excel(str(sys.argv[1]))
File "/Users/ben/PycharmProjects/Excel_writer/writer.py", line 17, in insert_to_excel
book = load_workbook(file_path)
File "/Users/ben/PycharmProjects/Excel_writer/venv/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 312, in load_workbook
reader = ExcelReader(filename, read_only, keep_vba,
File "/Users/ben/PycharmProjects/Excel_writer/venv/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 124, in __init__
self.archive = _validate_archive(fn)
File "/Users/ben/PycharmProjects/Excel_writer/venv/lib/python3.8/site-packages/openpyxl/reader/excel.py", line 96, in _validate_archive
archive = ZipFile(filename, 'r')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/zipfile.py", line 1251, in __init__
self.fp = io.open(file, filemode)
PermissionError: [Errno 1] Operation not permitted: '/Users/ben/Desktop/Ben_Test.xlsx'”
I've also added Automator and Finder to System Preferences > Security > Privacy > Accessibility. I've tried adding Automator to Full Disk Access as well as changing the permissions to 777 on the .xlsx file but I still get the error.