forked from eczarny/spectacle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZKAccessibilityElementAdditions.m
32 lines (23 loc) · 1.27 KB
/
ZKAccessibilityElementAdditions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#import "ZKAccessibilityElementAdditions.h"
@implementation ZKAccessibilityElement (ZKAccessibilityElementAdditions)
+ (ZKAccessibilityElement *)frontMostWindowElement {
ZKAccessibilityElement *systemWideElement = [ZKAccessibilityElement systemWideElement];
ZKAccessibilityElement *applicationWithFocusElement = [systemWideElement elementWithAttribute: kAXFocusedApplicationAttribute];
ZKAccessibilityElement *frontMostWindowElement = nil;
if (applicationWithFocusElement) {
frontMostWindowElement = [applicationWithFocusElement elementWithAttribute: kAXFocusedWindowAttribute];
if (!frontMostWindowElement) {
NSLog(@"Invalid accessibility element provided, unable to determine the size and position of the window.");
}
} else {
NSLog(@"Failed to find the application that currently has focus.");
}
return frontMostWindowElement;
}
#pragma mark -
+ (NSString *)frontMostApplicationName {
ZKAccessibilityElement *systemWideElement = [ZKAccessibilityElement systemWideElement];
ZKAccessibilityElement *applicationWithFocusElement = [systemWideElement elementWithAttribute: kAXFocusedApplicationAttribute];
return [applicationWithFocusElement stringValueOfAttribute: kAXTitleAttribute];
}
@end