Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a sendKey for Mac in Python?

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?

like image 277
Yinan Avatar asked Nov 20 '09 13:11

Yinan


People also ask

Does Mac Have a Python interpreter?

You can run a Python interpreter by double-clicking on Applications / Utilities / Terminal and typing python3 (if you've installed a version of Python 3) or python (to use Python 2) in the window that opens up.

Can I use Mac terminal for Python?

On a Mac system, it is very straight-forward. All you need to do is open Launchpad and search for Terminal , and in the terminal, type Python and boom, it will give you an output with the Python version.

Can you run Python on Apple?

iOS does not have Python pre-installed, so you'll have to embed a copy of Python within your app. Additionally, iOS apps can't run arbitrary secondary processes, so you'll have to run the Python interpreter inside your app's process. That's quite possible, but it involves a good understanding of the Python runtime.


1 Answers

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)
like image 127
Yinan Avatar answered Oct 03 '22 22:10

Yinan