Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A few potentially useful references:</p> <ul> <li><a href="https://developer.apple.com/reference/appkit/1473806-nswindowlist" rel="nofollow noreferrer"><code>NSWindowList()</code></a></li> <li><a href="https://developer.apple.com/reference/appkit/nsworkspace/1579272-launchedapplications?language=objc" rel="nofollow noreferrer">NSWorkspace <code>-launchedApplications</code></a> and <a href="https://developer.apple.com/reference/appkit/nsworkspace/1534059-runningapplications?language=objc" rel="nofollow noreferrer"><code>+runningApplications</code></a></li> <li><a href="https://developer.apple.com/reference/coregraphics/1552209-cgwindowlistcreate" rel="nofollow noreferrer"><code>CGWindowListCreate()</code></a> and <a href="https://developer.apple.com/reference/coregraphics/1455137-cgwindowlistcopywindowinfo?language=objc" rel="nofollow noreferrer"><code>CGWindowListCopyWindowInfo()</code></a> (requires 10.5)</li> <li><code>CGSGetWindowProperty()</code> </li> </ul> <p><code>CGSGetWindowProperty</code> is <a href="https://github.com/MarkVillacampa/undocumented-goodness/blob/master/CoreGraphics/CGSPrivate.h" rel="nofollow noreferrer">not officially documented</a>, but I believe you can use it with the an item of <code>NSWindowList()</code> as follows (completely untested):</p> <pre><code>OSErr err; CGSValue titleValue; char *title; CGSConnection connection = _CGSDefaultConnection(); int windowCount, *windows, i; NSCountWindows(&amp;windowCount); windows = malloc(windowCount * sizeof(*windows)); if (windows) { NSWindowList(windowCount, windows); for (i=0; i &lt; windowCount; ++i) { err = CGSGetWindowProperty(connection, windows[i], CGSCreateCStringNoCopy("kCGSWindowTitle"), &amp;titleValue); title = CGSCStringValue(titleValue); } free(windows); } </code></pre> <p>In AppleScript, it's really easy:</p> <pre><code>tell application "System Events" to get the title of every window of every process </code></pre> <p>You can call applescript from within an application using <a href="https://developer.apple.com/reference/foundation/nsapplescript" rel="nofollow noreferrer">NSAppleScript</a> or use <a href="http://appscript.sourceforge.net/" rel="nofollow noreferrer">appscript</a> as an ObjC-AppleScript bridge. With Leopard, you can use the <a href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ScriptingBridgeConcepts/Introduction/Introduction.html" rel="nofollow noreferrer">Scripting Bridge</a> (more untested code):</p> <pre><code>SystemEventsApplication *systemEvents = [SBApplication applicationWithBundleIdentifier:@"com.apple.systemevents"]; SBElementArray *processes = [systemEvents processes]; for (SystemEventsProcess* process in processes) { NSArray *titles = [[process windows] arrayByApplyingSelector:@selector(title)]; } </code></pre> <p>You could even try it in one long call, if you don't care about readability.</p> <pre><code>SystemEventsApplication *systemEvents = [SBApplication applicationWithBundleIdentifier:@"com.apple.systemevents"]; NSArray *titles = [[[systemEvents processes] arrayByApplyingSelector:@selector(windows)] arrayByApplyingSelector:@selector(arrayByApplyingSelector:) withObject:@selector(title)]; </code></pre> <p>The compiler will complain that <code>@selector(title)</code> is the wrong type, but it should work. Hand roll some delegation and you could turn the call into <code>[[[systemEvents processes] windows] title]</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload