How and is it possible to open a document in a GUI text editor such as Word from a python script on a Mac? For example, do something like this:
Open x.txt in Word.app
How and is it possible to open a document in a GUI text editor such as Word from a python script on a Mac? For example, do something like this:
Open x.txt in Word.app
If you want to open a file with a specific application on Mac OS, you do:
$ open -a appName fileName
So, for example you want to open hello.docx
with Pages
app, you do:
$ open -a pages path/hello.docx
Similarly to open a file with Word:
$ open -a "Microsoft Word.app" path/hello.docx
Now, we need to be able to call shell commands from Python. There are several ways of doing it. You can see this question for a variety of ways.
One simple way of doing it would be:
>>> import os
>>> os.system('open -a "Microsoft Word.app" path/hello.docx')