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

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

问题描述

我想在 Mac OS 中使用 Python 打开 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天全站免登陆