window name not available in macOS 10.15

Hi,


By enumerating desktop windows in Xcode,

In macOS 10.14.6, it is easy to get window name by window number.

In macOS 10.15.1, it is unable to get window name in the same flow. (ref. source code below)


---------------------------------------------------------------------------------

CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);

for (NSMutableDictionary* entry in (__bridge NSArray*)windowList)

{

NSString* owner = [entry objectForKey:(id)kCGWindowOwnerName];

NSString* Name = [entry objectForKey:(id)kCGWindowName];

NSString* ownerPID = [entry objectForKey:(id)kCGWindowOwnerPID];

NSInteger win_num = [[entry objectForKey:(id)kCGWindowNumber] integerValue];

if( num == win_num )

{

ownerName = owner; //ex: "Finder"

windowName = Name; // "nil" in macOS 10.15.1

NSLog(@"drag window found: %@, %@: %d", ownerName, windowName, (int)win_num);

break;

}


}

CFRelease(windowList);

---------------------------------------------------------------------------------


"windowName" is necessary along with "ownerName" to move desktop window to specified position by Apple script.

I try to have my app get “Accessibility” priviledge in “Security & Privacy” panel, but in vain.

How to get "windowName" in macOS 10.15.x ?

Is there other way to move window in macOS 10.15 or above?


Sincerely,

Yiming

Access to the

kCGWindowName
string seems to be gated by the Screen Recording user data protection. Once I got that, I received window names just fine on 10.15.

See WWDC 2019 Session 701 Advances in macOS Security for more on this.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi,

Thanks for your kindly update.
It works after app have "Screen Recording" priviledge granted.
Sincerely,
Cheers~
Yiming

window name not available in macOS 10.15
 
 
Q