如何使用Python获取OSX进程的ProcessSerialNumber?

如何使用Python获取OSX进程的ProcessSerialNumber?,python,macos,Python,Macos,我正在尝试使用CGEventPostToPSN发布事件,但在获取正确的进程序列号时遇到问题。我通过NSWorkspace.sharedWorkspace().launchedApplications()找到了我关心的进程,但我不知道将什么作为processSerialNumber参数传递给CGEventPostToPSN 我看到了NSApplicationProcessSerialNumberHigh和NSApplicationProcessSerialNumberLow字段,但我不确定如何处理

我正在尝试使用CGEventPostToPSN发布事件,但在获取正确的进程序列号时遇到问题。我通过NSWorkspace.sharedWorkspace().launchedApplications()找到了我关心的进程,但我不知道将什么作为processSerialNumber参数传递给CGEventPostToPSN

我看到了NSApplicationProcessSerialNumberHigh和NSApplicationProcessSerialNumberLow字段,但我不确定如何处理它们。我尝试将它们作为(NSApplicationProcessSerialNumberHigh,NSApplicationProcessSerialNumberLow)的元组传递,但似乎没有任何效果

代码如下所示:

from AppKit import NSWorkspace
from Quartz.CoreGraphics import CGEventPostToPSN
from Quartz.CoreGraphics import kCGMouseButtonLeft
from Quartz.CoreGraphics import CGEventCreateMouseEvent

my_process = filter(lambda x: x, [x if x.get('NSApplicationName') == 'My Process' else None for x in  NSWorkspace.sharedWorkspace().launchedApplications()])[0]
high_psn = my_process.get('NSApplicationProcessSerialNumberHigh')
low_psn = my_process.get('NSApplicationProcessSerialNumberLow')
my_psn = (high_psn, low_psn)
theEvent = CGEventCreateMouseEvent(None, type, (posx, posy), kCGMouseButtonLeft)
CGEventPostToPSN(my_psn, theEvent)

有人有想法吗?

是否有一个
ProcessSerialNumber
对象具有
HighLongOfsN
LowlongOfsN
字段,如Objective-C?