如何刷新取景器窗口?

发布于 2024-12-27 15:47:11 字数 614 浏览 7 评论 0原文

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

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

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

但这个功能也不起作用。

有人可以帮我吗?

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心意如水 2025-01-03 15:47:11

您是否在 executeAndReturnError: 调用之后检查了 err 字典的值?

正确的 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;
}

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

The correct AppleScript syntax would be:

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文