网上参考的都是以下脚本,但是在 m1 中并没有 python2 安装在 /usr/bin/python ,有大佬指条明路吗,一天能碰到 5 次以上 1 、使用 pyenv 安装的 py2.7.18 环境执行报错 2 、将 pyenv 的 ln -s 也是报错 sh-3.2# ln -s /Users/xxx/.pyenv/versions/2.7.18/bin/python2.7 /usr/bin/python ln: /usr/bin/python: Operation not permitted
参考: https://www.v2ex.com/t/743899
'''python
try: from AppKit import NSWorkspace except ImportError: print "Can't import AppKit -- maybe you're running python from brew?" print "Try running with Apple's /usr/bin/python instead." exit(1)
from datetime import datetime from time import sleep
last_active_name = None while True: active_app = NSWorkspace.sharedWorkspace().activeApplication() if active_app['NSApplicationName'] != last_active_name: last_active_name = active_app['NSApplicationName'] print '%s: %s [%s]' % ( datetime.now().strftime('%Y-%m-%d %H:%M:%S'), active_app['NSApplicationName'], active_app['NSApplicationPath'] ) sleep(1)
'''




