Created
March 14, 2018 17:34
-
-
Save javadoug/ca53c0c9772f71c8d3690f57d87cf58a to your computer and use it in GitHub Desktop.
AXUIElementAXValue in swift 4 MacOS SDK 12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AXUIElementAXValue { | |
private class func copyAXValue<T>(_ value: AXValue, type: AXValueType, _ handler: (_ memory: T?) -> T) -> T { | |
let val = UnsafeMutablePointer<T?>.allocate(capacity: 1) | |
AXValueGetValue(value, type, val) | |
let ret = handler(val.pointee) | |
val.deallocate(capacity: 1) | |
return ret | |
} | |
class func asCGRect(value: AXValue) -> CGRect { | |
return copyAXValue(value, type: AXValueType.cgRect, {(memory) -> CGRect in | |
if let mem = memory { | |
return mem | |
} else { | |
return CGRect.zero | |
} | |
}) | |
} | |
class func asCGPoint(value: AXValue) -> CGPoint { | |
return copyAXValue(value, type: AXValueType.cgPoint, {(memory) -> CGPoint in | |
if let mem = memory { | |
return mem | |
} else { | |
return CGPoint.zero | |
} | |
}) | |
} | |
class func asCFRange(value: AXValue) -> CFRange { | |
return copyAXValue(value, type: AXValueType.cfRange, {(memory) -> CFRange in | |
if let mem = memory { | |
return mem | |
} else { | |
return CFRange(location: 0, length: 0) | |
} | |
}) | |
} | |
class func asCGSize(value: AXValue) -> CGSize { | |
return copyAXValue(value, type: AXValueType.cgSize, { (memory) -> CGSize in | |
if let mem = memory { | |
return mem | |
} else { | |
return CGSize.zero | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist inspired by https://gist.github.com/c9iim/904a184921bb00bda759