Dion
Dion

Reputation: 3335

Focus Finder by Mac App

I have a little Updater in my mac app, which automatically downloads a dmg-file with the latest version of the app. Now it also works to open this file, but how can I focus the Finder window? Otherwise the user wouldn't know that the dog-file was opened, because it is in the background. This is the code I have for downloading and opening the file:

NSData *fileData = [NSData dataWithContentsOfURL:
                       [NSURL URLWithString:@"http:// ... .dmg"]];
    if([fileData writeToFile:@"/file.dmg" atomically:NO]) {
        [[NSWorkspace sharedWorkspace] openFile:@"file.dmg"];
        // Here I want to focus the new Finder window which has been opened by the code above
exit(1);
    }

Upvotes: 0

Views: 439

Answers (2)

Richard J. Ross III
Richard J. Ross III

Reputation: 55543

You could probably use

[[NSWorkspace sharedWorkspace] openFile:myFile withApplication:@"Finder"];

Upvotes: 5

Guillaume
Guillaume

Reputation: 21736

You need to use the method activateFileViewerSelectingURLs: from NSWorkspace (documentation).

You will find how to use it in my showinfinder project on GitHub.

Upvotes: 2

Related Questions