It's because you need to change the current working directory, not just give an absolute path to the command.
subprocess.Popen(["/Applications/LibreOffice.app/Contents/MacOS/soffice", "--convert-to", "pdf", "--outdir", "{output_folder} ", "{path_to_docx_file}/{title}.docx"])
Should be replaced with:
subprocess.Popen(["soffice", "--convert-to", "pdf", "--outdir", "{output_folder} ", "{path_to_docx_file}/{title}.docx"], cwd="/Applications/LibreOffice.app/Contents/MacOS/")
Even if it seems to be quite similar, there's a major difference between those two calls: the current working directory.
With the script:
subprocess.Popen(["/Applications/LibreOffice.app/Contents/MacOS/soffie", "--convert-to", "pdf", "--outdir", "{output_folder} ", "file.docx"])
If you're calling the python script in the ~ directory, it will try to reach ~/file.docx.
But, in the second one :
subprocess.Popen(["soffice", "--convert-to", "pdf", "--outdir", "{output_folder} ", "file.docx"], cwd="/Applications/LibreOffice.app/Contents/MacOS/")
It will try to reach the file in "/Applications/LibreOffice.app/Contents/MacOS/file.docx", which is the same behaviour of what you're doing with the cd
command (in fact, the cd command changes the current directory, so giving the cwd argument is the same as making a cd
call).
You can also use absolute paths for all your files and it will solve the problem too but it's not what you're trying to do. It depends on the software you are trying to build and it's purpose.
It's why the prompt says that the file does not exist. The program can't find the file in WHERE_YOU_CALL_THE_SCRIPT/{path_to_docx_file}/{title}.docx
because I suppose that the file is in /Applications/LibreOffice.app/Contents/MacOS/{path_to_docx_file}/{title}.docx
.