まじすか!

Finderでファイルを表示。

[[NSWorkspace sharedWorkspace] selectFile:fullPath inFileViewerRootedAtPath:@""];

全く存在に気付いてなかった。AppleEvent投げてた。無駄(w。


Finderの情報パネル表示は多分ない。のでAppleEvent投げてる。

@interface NSWorkspace(HMCocoaExtention)
- (BOOL)showInformationInFinder:(NSString *)path;
@end

@implementation NSWorkspace(HMCocoaExtention)
inline static NSAppleEventDescriptor *fileDescriptor(NSString *filePath)
{
    NSAppleEventDescriptor *fileDesc;
    NSAppleEventDescriptor *fileNameDesc;
    NSURL *fileURL = [NSURL fileURLWithPath:filePath];
    const char *fileURLCharP;
    
    fileURLCharP = [[fileURL absoluteString] fileSystemRepresentation];
    fileNameDesc = [NSAppleEventDescriptor descriptorWithDescriptorType:typeFileURL
                                                                  bytes:fileURLCharP
                                                                 length:strlen(fileURLCharP)];
    
    fileDesc = [NSAppleEventDescriptor objectSpecifierWithDesiredClass:cFile
                                                             container:nil
                                                               keyForm:formName
                                                               keyData:fileNameDesc];
    return fileDesc;
}
- (BOOL)showInformationInFinder:(NSString *)filePath
{
    NSAppleEventDescriptor *ae;
    OSStatus err = noErr;
    
    ae = [NSAppleEventDescriptor appleEventWithEventClass:kCoreEventClass
                                                  eventID:kAEOpenDocuments
                                            targetAppName:@"Finder"];
    if(!ae) {
        NSLog(@"Can NOT create AppleEvent.");
        return NO;
    }
    
    NSAppleEventDescriptor *fileInfoDesc = [NSAppleEventDescriptor
                                            objectSpecifierWithDesiredClass:cProperty
                                            container:fileDescriptor(filePath)
                                            keyForm:cProperty
                                            keyData:[NSAppleEventDescriptor descriptorWithTypeCode:cInfoWindow]];
    
    [ae setParamDescriptor:fileInfoDesc
                forKeyword:keyDirectObject];
    
    // activate Finder
    [self launchApplication:@"Finder"];
    @try {
        err = [ae sendAppleEventWithMode:kAENoReply | kAENeverInteract
                          timeOutInTicks:kAEDefaultTimeout
                                  replay:NULL];
    }
    @catch (NSException *ex) {
        if(![[ex name] isEqualTo:HMAEDescriptorSendingNotAppleEventException]) {
            @throw;
        }
    }
    @finally {
        if( err != noErr ) {
            NSLog(@"AESendMessage Error. Error NO is %d.", err );
        }
    }
        
    return err == noErr;
}
@end

長過ぎた(w
NSAppleEventDescriptorの拡張されたメソッドはmasakih/HMExtensions · GitHubこの辺。