实现:
可以使用的库是:applescript, 但是每执行一次tell.app()就会打开一个新终端,没办法连续性操作,网上的文档很少。
旧版库:appscript,据说已经停用
安装:
pip3 install applescript
源码:
from applescript import tell
#set what command you want to run here
yourCommand = 'ls'
tell.app( 'Terminal', 'do script"' + yourCommand + '"' , background = True)
tell.app( 'Terminal', 'do script"' + "who" + '"')
官方文档 :
applescript · PyPIrun applescripthttps://pypi.org/project/applescript/
不执行指令,单纯用python打开一个终端
import os
os.system('open -a Terminal .')