#import "StartRecordingAction.h" #import NS_ASSUME_NONNULL_BEGIN @implementation StartRecordingAction - (QSObject *)startRecordingFor:(QSObject *)directObject { id window = [directObject objectForType:kWindowsType]; if (!window) { NSLog(@"Could not get a window ID."); return directObject; } AXUIElementRef windowElement = (AXUIElementRef)window; CFTypeRef positionValue = NULL; CFTypeRef sizeValue = NULL; AXError positionError = AXUIElementCopyAttributeValue(windowElement, kAXPositionAttribute, &positionValue); AXError sizeError = AXUIElementCopyAttributeValue(windowElement, kAXSizeAttribute, &sizeValue); if (positionError == kAXErrorSuccess && sizeError == kAXErrorSuccess) { CGPoint position; CGSize size; if (AXValueGetValue(positionValue, kAXValueCGPointType, &position) && AXValueGetValue(sizeValue, kAXValueCGSizeType, &size)) { CGRect mainDisplayBounds = CGDisplayBounds(CGMainDisplayID()); CGFloat displayHeight = mainDisplayBounds.size.height; CGFloat flippedY = displayHeight - position.y - size.height; NSString *capturaURL = [NSString stringWithFormat:@"captura:?action=record&auto_start=true&x=%.0f&y=%.0f&width=%.0f&height=%.0f", position.x, flippedY, size.width, size.height]; NSURL *url = [NSURL URLWithString:capturaURL]; if (url) { [[NSWorkspace sharedWorkspace] openURL:url]; } else { NSLog(@"Failed to create valid URL"); } } } else { NSLog(@"Could not get size and position of window."); } if (positionValue) CFRelease(positionValue); if (sizeValue) CFRelease(sizeValue); return directObject; } @end NS_ASSUME_NONNULL_END