I want to get the current workspace in my app. I found a way to achieve my goal from valexa's answer:
-(int)spaceNumber
{
CFArrayRef windowsInSpace = CGWindowListCopyWindowInfo(kCGWindowListOptionAll | kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
for (NSMutableDictionary *thisWindow in (NSArray *)windowsInSpace) {
if ([thisWindow objectForKey:(id)kCGWindowWorkspace]){
return [[thisWindow objectForKey:(id)kCGWindowWorkspace] intValue];
}
}
return -1;
}
But now(macOS 10.13.3 for my case) the kCGWindowWorkspace is not existed any more. So are there any other ways to achieve my goal?
Thanks in advance!