Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The CGSPrivate.h header that's floating around isn't directly compatible with OS X 10.8 in that CGSGetWindowProperty() no longer exists (well, it does, but you can't link to it anymore). So add these two lines to the CGSPrivate.h file -- I went ahead and figured this out myself after many hours searching Google -- to get it to work:</p> <pre class="lang-c prettyprint-override"><code>extern CGSConnection CGSDefaultConnectionForThread(void); extern CGError CGSCopyWindowProperty(const CGSConnection cid, NSInteger wid, CFStringRef key, CFStringRef *output); </code></pre> <p>Adapting outis's code, here's a way of iterating through each window title. I have tested this with clang 4.2 on Mountain Lion:</p> <pre class="lang-c prettyprint-override"><code>CFStringRef titleValue; CGSConnection connection = CGSDefaultConnectionForThread(); NSInteger windowCount, *windows; NSCountWindows(&amp;windowCount); windows = (NSInteger*) malloc(windowCount * sizeof(NSInteger)); if (windows) { NSWindowList(windowCount, windows); for (int i = 0; i &lt; windowCount; ++i) { CGSCopyWindowProperty(connection, windows[i], CFSTR("kCGSWindowTitle"), &amp;titleValue); if(!titleValue) //Not every window has a title continue; //Do something with titleValue here } free(windows); } </code></pre> <p>Some other stuff I found out includes the following:</p> <ol> <li>No window title exceeds 127 bytes.</li> <li>Window titles are encoded with kCFStringEncodingMacRoman</li> </ol> <p>So, if you want it as a C-string, write something like this:</p> <pre class="lang-c prettyprint-override"><code>char *cTitle[127] = {0}; CFStringGetCString(titleValue,cTitle,127,kCFStringEncodingMacRoman); </code></pre> <p>Personally, I'd recommend doing it this way since the Accessibility API is a total pain and requires extra permissions.</p> <p>Hope this helps someone! Cheers!</p>
    singulars
    1. This table or related slice is empty.
    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.
    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