0
votes

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);
    }
2
What about –openFile:withApplication:? I don't work with OSX much, but I think that should do what you need. - Richard J. Ross III
Yes, perfect. Thank you! If you add this as an answer I'll mark it as correct. - Dion

2 Answers

5
votes

You could probably use

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

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

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