如何使用Python在Mac OS中打开应用程序 [英] How to open an application in Mac OS using Python

查看:80
本文介绍了如何使用Python在Mac OS中打开应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Python在Mac OS中打开TextEdit或Firefox之类的应用程序,然后等到应用程序退出.我无法弄清楚打开应用程序并等待的确切命令.

I want to open an application like TextEdit or Firefox in Mac OS using Python and wait till the applications exits. I can't figure out exact command to open an app and wait.

推荐答案

我不知道如何在applescript中执行此操作,但是您可以使用/usr/bin/open UNIX级OS X命令来执行此操作.此代码段将打开TextEdit.app并进行阻止,等待其退出后再继续:

I don't know how to do it in applescript, but you can do this by using the /usr/bin/open UNIX-level OS X command. This snippet will open TextEdit.app and block, waiting for it to quit before continuing:

import subprocess

subprocess.call(
    ["/usr/bin/open", "-W", "-n", "-a", "/Applications/TextEdit.app"]
    )

查看打开的手册页( man open )和python 子流程模块文档以了解更多信息详细信息.

Look at the open man page (man open) and the python subprocess module documentation for more details.

这篇关于如何使用Python在Mac OS中打开应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆