我想在用户登录到Mac时启动python程序,并在从Mac注销时停止该程序。
我不仅要在系统启动时在登录注销中执行程序。
答案 0 :(得分:0)
import Quartz
d = Quartz.CGSessionCopyCurrentDictionary()
if d.get('CGSSessionScreenIsLocked') and d.get('CGSSessionScreenIsLocked') == 1:
print("Screen is locked")
elif not d.get('CGSSessionScreenIsLocked'):
print("Screen is unlocked")