Sailwww
V2EX  ›  问与答

[Mac] 用 api 获取的 frontmostapplication 在 QQ 界面时显示 /sbin/launch

  •  
  •   Sailwww · Feb 28, 2022 · 1303 views
    This topic created in 1535 days ago, the information mentioned may be changed or developed.

    最近想写个电脑使用时间监控的小程序,写好后测试发现没什么问题,对于大部分界面程序表现为:

    • 激活时正常获得程序的 name,title,cmdline,pid,ppid
    • 如果 ctrl+w 关闭(无焦点状态),显示 pid=0,ppid=0 ,name 空, title 空,cmdline=/sbin/launch
    • 如果鼠标点击的方式切换界面,则按新焦点进程获取

    但是在 QQ 界面时,行为相反,即,有焦点时显示 /sbin/launch ,无焦点(直接 ctrl+w )时显示 qq 进程名

    方法是用 go 内嵌 Object-C 调用 frontmostApplication 得到的 pid

    [[NSWorkspace sharedWorkspace] frontmostApplication];
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   952 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 21:47 · PVG 05:47 · LAX 14:47 · JFK 17:47
    ♥ Do have faith in what you're doing.