Search code examples
objective-cxcodefocusfinder

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);
    }

Solution

  • You could probably use

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