AppleEvent keyDirectObject does not work the way I expect

I'm trying to get the URL used to launch an application. (Quinn helped me do the other part of this -- getting information about who sent the event -- in a TSI.)

In the will-finish-launching method in the app delegate, I do:

        eventManager.setEventHandler(self, andSelector: #selector(handleGetURLEvent(_:withReplyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))

And that does work: it launches the application if it's not running, and switches over to it if it is running. But... when I try to use keyDirectObject to get the URL it doesn't work -- I get nil as the result. But if I iterate through the event's items... I find the item.

        #if false
        let url = event.attributeDescriptor(forKeyword: keyDirectObject)
        print(url)
        #else
        let count = event.numberOfItems
        print("\(count) items")
        for index in 1...count {
            let keyword = event.keywordForDescriptor(at: index)
            if keyword == keyDirectObject {
                if let d = event.atIndex(index), let str = d.stringValue {
                    url = URL(string: str)
                    break
                }
            }
        }
        #endif

Later on (and this was due to Quinn), I have

        guard let aeAuditToken = event.attributeDescriptor(forKeyword: keySenderAuditTokenAttr)

and that works, so I don't think I'm asking for the URL incorrectly.

Any ideas?

Nobody has any thoughts about this? 😩

AppleEvent keyDirectObject does not work the way I expect
 
 
Q