Is there a sendKey for Mac in Python?

Yinan picture Yinan · Nov 20, 2009 · Viewed 18.1k times · Source

In Mac 10.6, I want to cause an active application to become de-active, or minimized by Python

I know I could use sendKey in Windows with Python, then what about in Mac?

Answer

Yinan picture Yinan · Nov 20, 2009

Here is what I found from a different question on Stack Overflow. It works pretty good for my problem.

import os
cmd = """
osascript -e 'tell application "System Events" to keystroke "m" using {command down}' 
"""
# minimize active window
os.system(cmd)