如何从AppleScript的WINDOWID [英] how to get windowid from applescript

查看:440
本文介绍了如何从AppleScript的WINDOWID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让每一个窗口的窗口ID。

I am trying to get window id of of every window.

set r to {}
tell application "System Events"
    repeat with t in windows of processes
        set sid to id of t
        set end of r to {title:title of t, id:sid}
    end repeat
end tell
r

以上code返回

The above code returns

错误系统事件得到了一个错误:无法让每一个过程的每一个窗口的第1项的ID。从每一个过程的每一个窗口的第1项的ID号-1728

error "System Events got an error: Can’t get id of item 1 of every window of every process." number -1728 from id of item 1 of every window of every process

如何让每一个窗口的窗口ID?

How to get the window id of every window?

推荐答案

我写了一个小的Objective-C程序为您获得窗口所有者,窗口名称和窗口的ID:

I wrote a little Objective-C program for you that gets the window owners, window names and window ids:

////////////////////////////////////////////////////////////////////////////////
// windowlist.m
// Mark Setchell
//
// Get list of windows with their WindowOwnerNames, WindowNames and WindowNumbers
//
// Compile with:
// clang windowlist.m -o windowlist -framework coregraphics -framework cocoa
//
// Run with:
// ./windowlist
//
// You can then run "screencapture" to capture that window:
//
// screencapture -l<windowid> -x someFile.[png|jpg|tif]
////////////////////////////////////////////////////////////////////////////////
#include <Cocoa/Cocoa.h>
#include <CoreGraphics/CGWindow.h>

int main(int argc, char **argv)
{
   NSArray *windows = (NSArray *)CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements|kCGWindowListOptionOnScreenOnly,kCGNullWindowID);
   for(NSDictionary *window in windows){
      int WindowNum = [[window objectForKey:(NSString *)kCGWindowNumber] intValue];
      NSString* OwnerName = [window objectForKey:(NSString *)kCGWindowOwnerName];
      NSString* WindowName= [window objectForKey:(NSString *)kCGWindowName];
      printf("%s:%s:%d\n",[OwnerName UTF8String],[WindowName UTF8String],WindowNum);
   }
}

输出

./windowlist

Preview:(null):300
Safari:(null):48
Terminal:(null):231
VirtualBox:(null):212
Mail:(null):150
Dropbox:(null):181
Finder:(null):118
Notification Center:(null):83
Google Drive:(null):73
Copy:(null):68
InkServer:(null):49
iTerm:(null):44
Google Drive::69
Copy::66
Dropbox::63
Creative Cloud::57
Spotlight::41
SystemUIServer::33
SystemUIServer:(null):36
SystemUIServer::31
Window Server:Menubar:3
Dock:Dock:23
iTerm:2. bash:190
iTerm:1. bash:336

这篇关于如何从AppleScript的WINDOWID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆