Just wondering if it is possible to configure a secondary macbook to act as a run destination in Xcode, similar to how you would configure an iPhone as a run destination.
I have tried connecting my device via USB-C and I can see that my macbook detects the second macbook via USB but it does not show up when trying to add devices in Xcode. I suppose this flow might not be supported?
Posts under macOS tag
200 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I'm working on a build system similar to Bazel where each build action runs in a sandbox. The sandbox contains only the files that the user defined as input to ensure that the build action doesn't have any implicit dependencies. Bazel achieves this by creating a "symlink forest" to the original source files. This works, but I have observed fseventsd using significant CPU during a Bazel build, presumably because of all the symlinks that get created.
Is there a way to disable file events for a directory or a volume? The "File System Events Programming Guide" in the Documentation Archive mentions placing an empty file named no_log in the .fseventsd directory at the root of the volume, but when testing on macOS 15.5 with APFS that appears to no longer work.
Related, is a "symlink forest" the best way to create a sandbox like this? Or is there a different method one can use to provide a view of a subset of the files in a directory tree? I read up on the App Sandbox but that seems too coarse grained. Something like Linux's overlayfs would work well, and maybe one can achieve a similar functionality with firmlinks? Curious about folks thoughts here.
Thanks in advance!
My app cannot be launched on some users' MacOS, it says "Library not loaded: /usr/lib/libc++.1.dylib".
"exception" : {"codes":"0x0000000000000000, 0x0000000000000000","rawCodes":[0,0],"type":"EXC_CRASH","signal":"SIGABRT"},
"termination" : {"code":1,"flags":518,"namespace":"DYLD","indicator":"Library missing","details":["(terminated at launch; ignore backtrace)"],"reasons":["Library not loaded: \/usr\/lib\/libc++.1.dylib","Referenced from: <E4CB6764-8CB9-32E9-881B-252E2F3E0C4B> \/Applications\/myapp.app\/Contents\/MacOS\/myapp","Reason: tried: '\/System\/iOSSupport\/usr\/lib\/libc++.1.dylib' (no such file), '\/System\/Volumes\/Preboot\/Cryptexes\/OS\/System\/iOSSupport\/usr\/lib\/libc++.1.dylib' (no such file), '\/System\/iOSSupport\/usr\/lib\/libc++.1.dylib' (no such file, no dyld cache), '\/usr\/lib\/libc++.1.dylib' (no such file), '\/System\/Volumes\/Preboot\/Cryptexes\/OS\/usr\/lib\/libc++.1.dylib' (no such file), '\/usr\/lib\/libc++.1.dylib' (no such file, no dyld cache)"]},
User 1's environment: 2020 MacBook Air, M1, system version 15.4.
User 2's environment: 2020 MacBook Pro, M1, system version: 15.5.
I (and the people around me) cannot reproduce this problem. It can be reproduced on User 2's computer, but the performance is strange, sometimes good and sometimes bad. The app can be launched normally during the day, and it can also be launched normally after restarting the computer. But it cannot be launched from 21:00 to 22:00 at night, and the problem still exists even if the computer is restarted.
After some searching, I suspect that there is a bug in the dynamic linker cache mechanism of MacOS, but we cannot confirm it. According to the official documentation: https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes
New in macOS Big Sur 11.0.1, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail. Instead, check for library presence by attempting to dlopen() the path, which will correctly check for the library in the cache. (62986286)
I also tried to manually copy libc++.1.dylib to the above path, but these paths are read-only, and files cannot be copied into them even if SIP is turned off.
Is there any other way to fix or avoid this problem? Thank you.
Other similar questions:
https://developer.apple.com/forums/thread/756370
https://developer.apple.com/forums/thread/764824
Hey folks
I'm trying to use .onDrop() on a view that needs to accept files. This works fine, I specify a supportedContentTypes of [.fileURL] and it works great.
I got a request to add support for dragging the macOS screenshot previews into my app and when I looked at it, they aren't available as a URL, only an image, so I changed my array to [.fileURL, .image].
As soon as I did that, I noticed that dragging any image file, even from Finder, calls my onDrop() closure with an NSItemProvider that only knows how to give me an image, with no suggestedName.
Am I missing something here? I had been under the impression that:
The order of my supportedContentTypes indicates which types I prefer (although I now can't find this documented anywhere)
Where an item could potentially vend multiple UTTypes, the resulting NSItemProvider would offer up the union of types that both it, and I, support.
If it helps, I put together a little test app which lets you select which UTTypes are in supportedContentTypes and then when a file is dragged onto it, it'll tell you which content types are available - as far as I can tell, it's only ever one, and macOS strongly prefers to send me an image vs a URL.
Is there anything I can do to convince it otherwise?
Has anyone here successfully set up macOS as a globally accessible, multiuser development server using native remote login (SSH) and VS Code Remote?
I have a macOS application developed in SwiftUI. It's a document-based application. I know how to hide the Show Tab Bar command under View. I don't want to hide it. I always want to show tabs. I wonder how to enable this command programmatically such that the document window always has the + button to the right. Thanks.
Hello! I need to clarify whether it is currently possible to build a browser based on Chromium and upload it to the App Store or TestFlight for MacOS?
At the moment, when trying to build the browser with App Sandbox function, an error appears:
[2849:52739:0416/142702.300453:FATAL:mach_port_rendezvous.cc(410)] Check failed: kr == KERN_SUCCESS. bootstrap_check_in com.name.namebrowser.MachPortRendezvousServer.2849: Permission denied (1100)
In SwiftUI for macOS, how can I hide the tab bar when using TabView? I would like to provide my own tab bar implementation.
In AppKit's NSTabViewController, we can do the following:
let tabViewController = NSTabViewController()
tabViewController.tabStyle = .unspecified
I've come across various posts that suggest using the .toolbar modifier, but none appear to work on macOS (or at least I haven't found the right implementation).
struct ContentView: View {
var body: some View {
TabView {
// ... content
} <- which view modifier hides the tab bar?
}
}
Latest macOS, Latest Xcode
I have a macOS app that captures screen images. The first time I run this application, a dialog is shown directing the user to give my app Screen Recording permission. Is there a way I can trigger this dialog earlier and detect whether the permission was granted?
We have a launch daemon which can check for team identifier and some other signing information of any application on machine and match it with provided information to confirm the validity of the application/binary. We use SecStaticCodeCreateWithPath to read the signing information of the app/binary which works in most cases.
However, for some third party daemon processes, the static code creation fails with error "Operation not permitted". We are having difficult time identifying why static code creation would fail specially when our process is running with root privileges.
Can you please help us understand in what scenario can this API fail with this error? Can there be any process or rule which can deny creating static code of a process like endpoint security extensions/daemon?
We are using default flags in SecStaticCodeCreateWithPath.
Hello everyone,
I'm currently in the process of implementing platform SSO (Single Sign-On) in macOS and could use some guidance. I find myself a bit confused during the device registration phase, particularly because my Identity Provider (IdP) needs to support it. I'm wondering if Platform SSO will handle this automatically or if there are specific steps I need to take.
Additionally, I'm unsure whether I need to share the device signing and encryption key in my identity. Could someone please clarify this for me?
Finally, I would greatly appreciate it if someone could provide me with some sample code or starting pointers to help me get started on the right track. More into apart from OpenID, SAML protocol what else the Idp needs to change to support Platform SSO.
Thank you in advance for your assistance!
While adopting SwiftUI (and Swift Concurrency) into a macOS/AppKit application, I'm making extensive use of the .task(id:) view modifier.
In general, this is working better than expected however I'm curious if there are design patterns I can better leverage when the number of properties that need to be "monitored" grows.
Consider the following pseudo-view whereby I want to call updateFilters whenever one of three separate strings is changed.
struct FiltersView: View {
@State var argument1: String
@State var argument2: String
@State var argument3: String
var body: some View {
TextField($argument1)
TextField($argument2)
TextField($argument3)
}.task(id: argument1) {
await updateFilters()
}.task(id: argument2) {
await updateFilters()
}.task(id: argument3) {
await updateFilters()
}
}
Is there a better way to handle this? The best I've come up with is to nest the properties inside struct. While that works, I now find myself creating these "dummy types" in a bunch of views whenever two or more properties need to trigger an update.
ex:
struct FiltersView: View {
struct Components: Equatable {
var argument1: String
var argument2: String
var argument3: String
}
@State var components: Components
var body: some View {
// TextField's with bindings to $components...
}.task(id: components) {
await updateFilters()
}
}
Curious if there are any cleaner ways to accomplish this because this gets a bit annoying over a lot of views and gets cumbersome when some values are passed down to child views. It also adds an entire layer of indirection who's only purpose is to trigger task(id:).
Crash Stack:
thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=1, subcode=0x19ba3bb04)
frame #0: 0x000000019ba3bb04 CoreFoundation`forwarding.cold.2 + 92
frame #1: 0x000000019b8ab718 CoreFoundation`forwarding + 1288
frame #2: 0x000000019b8ab150 CoreFoundation`_CF_forwarding_prep_0 + 96
frame #3: 0x000000019df230b0 CoreText`TCFRef<CTRun*>::Retain(void const*) + 40
frame #4: 0x000000019e052050 CoreText`CreateFontWithFontURL(__CFURL const*, __CFString const*, __CFString const*) + 476
frame #5: 0x000000019e052874 CoreText`TCGFontCache::CopyFont(__CFURL const*, __CFString const*, __CFString const*) + 144
frame #6: 0x000000019df27dcc CoreText`TBaseFont::CopyNativeFont() const + 232
frame #7: 0x000000019df8ee64 CoreText`TBaseFont::GetInitializedGraphicsFont() const + 152
frame #8: 0x000000019df26d70 CoreText`TBaseFont::CopyVariationAxes() const + 296
frame #9: 0x000000019df2d148 CoreText`TDescriptor::InitBaseFont(unsigned long, double) + 768
frame #10: 0x000000019df21358 CoreText`TDescriptor::CreateMatchingDescriptor(__CFSet const*, double, unsigned long) const + 604
frame #11: 0x000000019df251f8 CoreText`CTFontCreateWithFontDescriptor + 68
frame #12: 0x00000001bff8dfb8 WebCore`WebCore::createCTFont(__CFDictionary const*, float, unsigned int, __CFString const*, __CFString const*) + 124
frame #13: 0x00000001bff8e8bc WebCore`WebCore::FontPlatformData::fromIPCData(float, WebCore::FontOrientation&&, WebCore::FontWidthVariant&&, WebCore::TextRenderingMode&&, bool, bool, std::__1::variant<WebCore::FontPlatformSerializedData, WebCore::FontPlatformSerializedCreationData>&&) + 228
frame #14: 0x00000001c128eef4 WebKit`IPC::ArgumentCoder<WebCore::Font, void>::decode(IPC::Decoder&) + 1352
frame #15: 0x00000001c1333ca4 WebKit`std::__1::optional<***::HashMap<***::String, WebCore::AttributedString::AttributeValue, ***::DefaultHashWTF::String, ***::HashTraitsWTF::String, ***::HashTraitsWebCore::AttributedString::AttributeValue, ***::HashTableTraits>> IPC::ArgumentCoder<***::HashMap<***::String, WebCore::AttributedString::AttributeValue, ***::DefaultHashWTF::String, ***::HashTraitsWTF::String, ***::HashTraitsWebCore::AttributedString::AttributeValue, ***::HashTableTraits>, void>::decodeIPC::Decoder(IPC::Decoder&) + 480
frame #16: 0x00000001c1333a5c WebKit`std::__1::optional<***::HashMap<***::String, WebCore::AttributedString::AttributeValue, ***::DefaultHashWTF::String, ***::HashTraitsWTF::String, ***::HashTraitsWebCore::AttributedString::AttributeValue, ***::HashTableTraits>> IPC::Decoder::decode<***::HashMap<***::String, WebCore::AttributedString::AttributeValue, ***::DefaultHashWTF::String, ***::HashTraitsWTF::String, ***::HashTraitsWebCore::AttributedString::AttributeValue, ***::HashTableTraits>>() + 28
frame #17: 0x00000001c1333804 WebKit`std::__1::optional<std::__1::pair<WebCore::AttributedString::Range, ***::HashMap<***::String, WebCore::AttributedString::AttributeValue, ***::DefaultHashWTF::String, ***::HashTraitsWTF::String, ***::HashTraitsWebCore::AttributedString::AttributeValue, ***::HashTableTraits>>> IPC::Decoder::decode<std::__1::pair<WebCore::AttributedString::Range, ***::HashMap<***::String, WebCore::AttributedString::AttributeValue, ***::DefaultHashWTF::String, ***::HashTraitsWTF::String, ***::HashTraitsWebCore::AttributedString::AttributeValue, ***::HashTableTraits>>>() + 156
frame #18: 0x00000001c121f368 WebKit`IPC::ArgumentCoder<WebCore::AttributedString, void>::decode(IPC::Decoder&) + 172
frame #19: 0x00000001c121f124 WebKit`std::__1::optionalWebCore::AttributedString IPC::Decoder::decodeWebCore::AttributedString() + 28
frame #20: 0x00000001c12594ec WebKit`IPC::ArgumentCoder<WebCore::DictionaryPopupInfo, void>::decode(IPC::Decoder&) + 76
frame #21: 0x00000001c12d0660 WebKit`std::__1::optionalWebCore::DictionaryPopupInfo IPC::Decoder::decodeWebCore::DictionaryPopupInfo() + 28
frame #22: 0x00000001c12ceef0 WebKit`IPC::ArgumentCoder<WebKit::WebHitTestResultData, void>::decode(IPC::Decoder&) + 1292
frame #23: 0x00000001c1338950 WebKit`std::__1::optionalWebKit::WebHitTestResultData IPC::Decoder::decodeWebKit::WebHitTestResultData() + 28
frame #24: 0x00000001c1ec7edc WebKit`WebKit::WebPageProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 31392
frame #25: 0x00000001c1fb8f28 WebKit`IPC::MessageReceiverMap::dispatchMessage(IPC::Connection&, IPC::Decoder&) + 272
frame #26: 0x00000001c19ab2c0 WebKit`WebKit::WebProcessProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 44
frame #27: 0x00000001c1fb3254 WebKit`IPC::Connection::dispatchMessage(***::UniqueRefIPC::Decoder) + 252
frame #28: 0x00000001c1fb3768 WebKit`IPC::Connection::dispatchIncomingMessages() + 576
frame #29: 0x00000001b9ab90c4 JavaScriptCore`***::RunLoop::performWork() + 204
frame #30: 0x00000001b9ab9fec JavaScriptCore`***::RunLoop::performWork(void*) + 36
frame #31: 0x000000019b8cc8a4 CoreFoundation`CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 28
frame #32: 0x000000019b8cc838 CoreFoundation`__CFRunLoopDoSource0 + 176
frame #33: 0x000000019b8cc59c CoreFoundation`__CFRunLoopDoSources0 + 244
frame #34: 0x000000019b8cb138 CoreFoundation`__CFRunLoopRun + 840
frame #35: 0x000000019b8ca734 CoreFoundation`CFRunLoopRunSpecific + 588
frame #36: 0x00000001a6e39530 HIToolbox`RunCurrentEventLoopInMode + 292
frame #37: 0x00000001a6e3f348 HIToolbox`ReceiveNextEventCommon + 676
frame #38: 0x00000001a6e3f508 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 76
frame #39: 0x000000019f442848 AppKit`_DPSNextEvent + 660
frame #40: 0x000000019fda8c24 AppKit`-[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 688
frame #41: 0x000000019f435874 AppKit`-[NSApplication run] + 480
frame #42: 0x000000019f40c068 AppKit`NSApplicationMain + 888
frame #43: 0x00000001ca56a70c SwiftUI`merged generic specialization <SwiftUI.TestingAppDelegate> of function signature specialization <Arg[0] = Existential To Protocol Constrained Generic> of SwiftUI.runApp(__C.NSResponder & __C.NSApplicationDelegate) -> Swift.Never + 160
frame #44: 0x00000001ca9e09a0 SwiftUI`SwiftUI.runApp<τ_0_0 where τ_0_0: SwiftUI.App>(τ_0_0) -> Swift.Never + 140
frame #45: 0x00000001cad5ce68 SwiftUI`static SwiftUI.App.main() -> () + 224
frame #46: 0x0000000105943104 MyApp Dev.debug.dylib`static MyMacApp.$main() at :0
frame #47: 0x0000000105943c9c MyApp Dev.debug.dylib`main at MyMacApp.swift:24:8
frame #48: 0x000000019b464274 dyld`start + 2840
I tried using Pluginkit via terminal to determine if a File Provider Extension is enabled on Mac OS.
Although I see the extension listed in the output of pluginkit -m, The status of + or - doesn't seem to change in this output when I disable or enable the FileProvider extension in System Settings.
Is there a more reliable way to determine if the extension is enabled ?
Reproduction procedure
Launch Xcode and press shift+command+N to create a macOS App project.
Edit the generated ContentView.swift to the following content:
struct ContentView: View {
@State var txt: String = “”
var body: some View {
VStack {
Text(“Hello, world!\(txt)”)
TextField(“input”, text: $txt)
onSubmit { // lack of a period letter.
// .onSubmit { // Correct code
print(“onSubmit\(txt)”)
}
}
}
}
Build with command+B and it succeeds.
Debug with command+R, but a rainbow wheel appears and the window does not show.
An error is displayed in Xcode’s Preview Canvas, preventing preview.
@Quinn,
The application which is not made with Xcode, has a provision profile, but App Store Connect says "Not Available for Testing".
My Googlefu appears weak as I can't seem to figure out why this is, except that it mentions you need to be using Xcode 13 or newer.
Am guessing Xcode is adding some meta data to the Info.plist file which TestFlight requires.
Is it possible to know which keys and values are required to satisfy TestFlight?
If it's not plist keys, is there something else that's needed, that can be shared? We can do this privately if desired.
Hello, I'm having some problems when install my Packet Tunnel network extension as system extension on my mac(macos 15.0).
It stuck on Validation By Category. (it works well as NE app extension on ios)
systemextensionsctl list
--- com.apple.system_extension.network_extension
enabled active teamID bundleID (version) name [state]
<...> com.myteam.balabalabla.ne (1.0/1) - [validating by category]
This is my install System Extension Code sample
public class SystemExtension: NSObject, OSSystemExtensionRequestDelegate {
private let forceUpdate: Bool
private let inBackground: Bool
private let semaphore = DispatchSemaphore(value: 0)
private var result: OSSystemExtensionRequest.Result?
private var properties: [OSSystemExtensionProperties]?
private var error: Error?
private init(_ forceUpdate: Bool = false, _ inBackground: Bool = false) {
}
// some request function i overwrite
public func activation() throws -> OSSystemExtensionRequest.Result? {
let request = OSSystemExtensionRequest.activationRequest(forExtensionWithIdentifier: FilePath.packageName + ".myNeName", queue: .main)
request.delegate = self
OSSystemExtensionManager.shared.submitRequest(request)
semaphore.wait()
if let error {
throw error
}
return result
}
public func getProperties() throws -> [OSSystemExtensionProperties] {
let request = OSSystemExtensionRequest.propertiesRequest(forExtensionWithIdentifier: FilePath.packageName + ".myNeName", queue: .main)
request.delegate = self
OSSystemExtensionManager.shared.submitRequest(request)
semaphore.wait()
if let error {
throw error
}
return properties!
}
public nonisolated static func install(forceUpdate: Bool = false, inBackground: Bool = false) async throws -> OSSystemExtensionRequest.Result? {
try await Task.detached {
try SystemExtension(forceUpdate, inBackground).activation()
}.result.get()
}
public nonisolated static func uninstall() async throws -> OSSystemExtensionRequest.Result? {
try await Task.detached {
try SystemExtension().deactivation()
}.result.get()
}
}
// And other methods
I follow this post Your Friend the System Log and use this command line to collect log. After I initiated the system extension request
sudo log collect --last 5m
Here is my log (),I only pasted some code snippets that caught me, full version see attachments.(only include com.apple.sysextd), if need more, plz ask me.
1. Some policy missing
```log
22:00:13.818257 `sysextd` extension mockTeamID app.balabala.com.mockbalabala (1.0/1) advancing state from staging to validating
22:00:13.818263 sysextd returning cdhash for local arch arm64 of extension app.balabala.com.mockbalabala
info 2025-05-01 22:00:13.818336 sysextd Extension with identifier <private> reached state <private>
22:00:13.819185 sysextd [0x9a2034b00] activating connection: mach=false listener=false peer=false name=com.apple.CodeSigningHelper
22:00:13.819911 sysextd [0x9a2034b00] invalidated after the last release of the connection object
22:00:13.821024 sysextd making activation decision for extension with teamID teamID("mockTeamID ), identifier app.balabala.com.mockbalabala
22:00:13.821026 sysextd no related kext found for sysex `app.balabala.com.mockbalabala`
22:00:13.821027 sysextd no extension policy -- activation decision is UserOption
nesessionmanager.system-extensions interrupted
22:00:14.313576 sysextd [0x9a2178280] invalidated because the client process (pid 1886) either cancelled the connection or exited
22:00:14.542154 sysextd connection to com.apple.nesessionmanager.system-extensions interrupted
22:00:14.542319 sysextd [0x9a2178000] Re-initialization successful; calling out to event handler with XPC_ERROR_CONNECTION_INTERRUPTED
22:00:14.542351 sysextd connection to com.apple.nesessionmanager.system-extensions interrupted
22:00:14.589375 nesessionmanager [0x6c80e4500] activating connection: mach=true listener=false peer=false name=com.apple.sysextd
And when i debug the System Extension code i notice the request Error catch by didFailWithError
public func request(_: OSSystemExtensionRequest, didFailWithError error: Error) {
self.error = error
semaphore.signal()
}
error is
OSSystemExtensionErrorDomain code 1
This problem has been bothering me for a long time, I would appreciate any help, if need more info, comment, thank you.
Topic:
App & System Services
SubTopic:
Networking
Tags:
macOS
Network Extension
Network
System Extensions
(EN):
After upgrading to macOS 15+, the system contains two incompatible versions of the PingFang (苹方) font:
1. A system-provided version (/System/Library/Fonts/PingFang.ttc)
2. A user-installed version via Font Book (located in ~/Library/Fonts or /Library/Fonts)
When a user installs or removes the PingFang font via Font Book after the app starts, font resolution may switch, causing garbled text in newly opened windows or views.
This issue did not occur in macOS 13 or 14, and seems specific to how macOS 15+ handles system and user font overlays.
In SwiftUI for macOS, how can I animate the transition from one Tab to another Tab within TabView when the selection changes?
In AppKit, we can do the following:
let tabViewController = NSTabViewController()
tabViewController.transitionOptions = [.crossfade, .allowUserInteraction]
How can I achieve the same crossfade effect when using TabView?
I'm facing a bizarre issue with the Apple's Accessibility APIs. I am registering an AXObserver that listens for, among other things, the kAXSelectedTextChangedNotification. For many new users, the kAXSelectTextChangedNotification is not triggered, even though they have enabled Accessibility permission for the app. Other notifications are getting through (kAXWindowMovedNotification, kAXWindowResizedNotification, kAXValueChangedNotification etc - full list here), just not the kAXSelectedTextChangedNotification!
We've found that we can reproduce the error by removing accessibility permission for the app and rebooting our computers. After restarting and reenabling accessibility permissions, the kAXSelectedTextChangedNotification was not received, even though other notifications were fine.
Strangely, the issue can be resolved by launching Apple's Accessibility Inspector app on an impacted computer. Once the Accessibility Inspector is loaded, the kAXSelectedTextChangedNotifications start coming through as expected. This implies to me that either:
We are missing some needed setup when starting the observers. Accessibility Inspector gets it right, thus ‘starting’ the system properly.
Accessibility Inspector is using some Apple private APIs that we don’t have access to.
Things I’ve tried:
I've tried subscribing the AXSelectedTextChangedNotification to different AXUIElements, including the SystemWide element, the Application element, and children elements from the AXApplication. None of these received the kAXSelectedTextChangedNotification, until Accessibility Inspector is booted up. No surprises here, as Apple's documentation confirms that you should add the notification to the root Application AXUIElement if you want to receive notifications for all its children.
I had a theory that the issue might be due to my code calling AXUIElementCreateApplication multiple times, possibly creating multiple "Applications" in Apple's Accessibility implementation. If that’s the case, the notifications might be sent to the wrong application AXUIElement. However, refactoring my code to only call AXUIElementCreateApplication once didn't resolve the issue.
I thought the issue may be caused by subscribing the AXSelectedTextChangedNotification on the high-level application element (at odds with Apple's documentation). I've tried traversing the child AXUIElements until we find one with the kAXSelectedTextAttribute and then subscribing to that. This did not resolve the issue. I don’t think it's the correct path to continue exploring, given that the notifications are received correctly after AccessibilityInspector is launched.
There is one exception to the above: if I add the kSelectedTextChangedNotification listener to a specific text field AXUIElement, I do receive the notification on that text field. However, this is not practical; I need a solution that will work for all text fields within an app. The Accessibility Inspector appears to be doing something that causes the selected-text-changed notifications to be correctly passed up to the high-level application AXUIElement.
Another thought is that I could traverse the entire Accessibility hierarchy and add listeners to every subview that has the kAXSelectedTextAttribute. However, I don’t like this long-term solution. It will be slow and incomplete: new elements get added and removed frequently. I just want the kAXSelectedTextChangedNotification to be received by the high-level Application AXUIElement, which the documentation suggests it should be. I also have evidence that this can work, since notifications start coming through after Accessibility Inspector is launched. It’s just a matter of discovering how to replicate whatever Accessibility Inspector is doing.
An interesting wrinkle: I implemented the 'traverse' strategy above, but was surprised by how few elements were in the hierarchy. Most apps only go down ~2-3 levels, which didn't seem right to me. Perhaps the Accessibility tree isn't fully initialized? I tried adding a 5-second delay to allow more initialization time, but it didn't change anything.
Does anyone have any ideas? Here's our file.