问题
I am using the following two lines of Python code to open a new Terminal window from a Python script, and this works fine:
import os
os.system('open -a Terminal .')
Now I would like to pass the new Terminal window a command to be executed, for example
ls
How can I do that?
回答1:
Try this
import appscript
appscript.app('Terminal').do_script('ls') # or any other command you choose
来源:https://stackoverflow.com/questions/48408278/python-macos-open-new-terminal-window-from-python-passing-command-to-be-exec