For performance testing and improving my Find Any File app, when it sends tens of thousands of file references to an app via its “Pass Results” rule, I was attempting to make a simple app in Xcode that implements the application:openFiles: handler and that logs the number of items it has received.
And that works.
However, the app (or script) that passes the file references to the app’s “open” (odoc) handler, will always be stalled for 5 seconds during this invocation.
Here’s how I made the app:
Create a new Mac “App” project (ObjC) in Xcode, and implement in its AppDelegate.m:
-(void)application:(NSApplication *)sender openFiles:(NSArray<NSString *> *)filenames {
NSLog(@"open %ld files", filenames.count);
[NSApp replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
}
I run the app (I called it “Test.app”), which will open an empty default window, and then I invoke its “open” handler, either from FAF or via a simple AppleScript like this:
tell application "Test.app"
open {"/etc/hosts"}
end tell
The app’s openFiles: handler gets invoked immediately, adding a line to the log. But the script then keeps waiting until 5s have passed. Every time.
I also tried this with openURLs: instead. Same result.
Any idea what’s causing the delay?
BTW, I later realized that I can achieve my goal also with a simple AppleScript like this:
on open theFiles
display notification "open count: " & (count of theFiles)
end open
on run
delay 1
end run
But I’d still like to understand what’s causing the 5s delay in the ObjC project.
