我正在使用以下两行Python代码从Python脚本中打开一个新的终端窗口,这很好用:
import os
os.system('open -a Terminal .')
现在,我希望给新的终端窗口传递一个要执行的命令,例如:
ls
我该怎么做呢?
试试这个
import appscript
appscript.app('Terminal').do_script('ls') # or any other command you choose
由于旧答案已经过时,
如果您还没有下载,请下载AppleScript。
pip3 install applescript
Python脚本
from applescript import tell
#set what command you want to run here
yourCommand = 'ls'
tell.app( 'Terminal', 'do script "' + yourCommand + '"')
bash -c "ls; exec bash"
的起始点打开。我不熟悉 OS X,但在大多数 Linux 终端模拟器中,你可以通过标志传递它。 - Norrius