Par*_*fna 2 cocoa applescript finder macos-carbon objective-c
我想在Finder应用程序中刷新特定文件/文件夹的图标.
FNNotifyByPath( (const UInt8 *)folderPath, kFNDirectoryModifiedMessage, kNilOptions );  
Run Code Online (Sandbox Code Playgroud)
FNNotifyByPath不适合这个.现在我正在尝试使用appleScript  
+(void) refreshIconForItem : (NSString *)itemPath
{
    NSString *source=[NSString stringWithFormat:@"tell application \"Finder\" to update \"%@\"",[NSString stringWithUTF8String:itemPath]];
    NSAppleScript *update=[[NSAppleScript alloc] initWithSource:source];
    NSDictionary *err;
    [update executeAndReturnError:&err];
}
Run Code Online (Sandbox Code Playgroud)
但是这个功能也不起作用.
有人可以帮帮我吗?
你err在executeAndReturnError:通话后检查了字典的值吗?
正确的AppleScript语法是:
@"告诉应用程序\"Finder \"更新POSIX文件\"%@ \""
编辑添加:或者,您可以下载到AppleEvent级别:
OSStatus    SendFinderSyncEvent( const FSRef* inObjectRef )
{
    AppleEvent  theEvent = { typeNull, NULL };
    AppleEvent  replyEvent = { typeNull, NULL };
    AliasHandle itemAlias = NULL;
    const OSType    kFinderSig = 'MACS';
    OSStatus    err = FSNewAliasMinimal( inObjectRef, &itemAlias );
    if (err == noErr)
    {
        err = AEBuildAppleEvent( kAEFinderSuite, kAESync, typeApplSignature,
            &kFinderSig, sizeof(OSType), kAutoGenerateReturnID,
            kAnyTransactionID, &theEvent, NULL, "'----':alis(@@)", itemAlias );
        if (err == noErr)
        {
            err = AESendMessage( &theEvent, &replyEvent, kAENoReply,
                kAEDefaultTimeout );
            AEDisposeDesc( &replyEvent );
            AEDisposeDesc( &theEvent );
        }
        DisposeHandle( (Handle)itemAlias );
    }
    return err;
}
Run Code Online (Sandbox Code Playgroud)
        |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           1493 次  |  
        
|   最近记录:  |