NSWorkspace selectFile:inFileViewerRootedAtPath: does not work the first time it is called

1k Views Asked by At

I have a sandboxed Cocoa app. I noticed that when I call [[NSWorkspace sharedWorkspace] selectFile:path inFileViewerRootedAtPath:path] no Finder window opens the first time is called. Finder.app is brought to the foreground (menu bar changes to Finder), but otherwise nothing happens.

When I bring my app back to the front and again have it select a file in Finder, the Finder window opens with the file selected as expected. I tried this with @"" as second argument, same thing.

When a Finder window is open already, everything works as expected.

Has anybody else seen this problem? Workaround is to immediately call selectFile:... twice, but that doesn't seem right.

Edit: not related to sandboxing. Same issue without sandbox.

1

There are 1 best solutions below

0
On

I think activateFileViewerSelectingURLs is better. It correctly selects multiple files in the finder.