Post

Replies

Boosts

Views

Activity

Reply to Macos Application hangs when using NSDistributedNotificationCenter and CFRunLoopAddSource
Not sure if it is still an actual question but it is quite common one. There are few things here to be aware of: Your app must be trusted for accessibility. When AXIsProcessTrusted() returns false, it is a bad idea to use event taps with kCGEventTapOptionDefault. You may use kCGEventTapOptionListenOnly option (instead of kCGEventTapOptionDefault). If you're not going to prevent events from propagating further, you can use this option. It should not block any input even if AXIsProcessTrusted() is false. If you're going to prevent events from propagating, well, don't create tap until AXIsProcessTrusted() is true and make sure you remove the tap once it becomes false. Still there is a caveat. If the user revokes accessibility permission for your app by removing the app from the list (instead of unchecking the check box), AXIsProcessTrusted() continues to return true but the tap will hang.
Topic: UI Frameworks SubTopic: AppKit Tags:
Dec ’20
Reply to -[NSWorkspace openApplicationAtURL:configuration:completionHandler:] does not work
Figured it out. The login item quits too soon. It should wait for the open operation to be completed. Something like (not the best solution, for illustrative purpose only): [workspace openApplicationAtURL: [NSURL fileURLWithPath: path] configuration: configuration completionHandler:^(NSRunningApplication* app, NSError* error) { 	if (error) { 		NSLog(@"Failed to run the app: %@", error.localizedDescription); 	} 	exit(0); }]; [NSThread sleepForTimeInterval: 10];
Topic: UI Frameworks SubTopic: AppKit Tags:
Dec ’20