如何刷新Finder窗口? [英] How to refresh finder window?

查看:1243
本文介绍了如何刷新Finder窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要刷新在Finder应用程序特定的文件/文件夹图标。

I want to refresh icon for particular file/folder in Finder application.

FNNotifyByPath( (const UInt8 *)folderPath, kFNDirectoryModifiedMessage, kNilOptions );  

FNNotifyByPath 不工作这一点。
我现在想用的AppleScript

FNNotifyByPath is not working for this. Now i am trying with 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];
}

但这种功能也不能正常工作。

but this function is also not working.

任何人都可以请帮我吗?

Can anyone please help me out?

推荐答案

你是否检查了 executeAndReturnError后 ERR 词典的值:打电话?

Did you check the value of the err dictionary after the executeAndReturnError: call?

正确的AppleScript语法是:

The correct AppleScript syntax would be:

@告诉应用程序\\查找\\更新POSIX文件\\%@ \\

@"tell application \"Finder\" to update POSIX file \"%@\""

编辑补充:或者,你能下降到的AppleEvent级别:

EDIT TO ADD: Alternately, you could drop down to the AppleEvent level:

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

这篇关于如何刷新Finder窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆