gpt4 book ai didi

objective-c - 如何刷新取景器窗口?

转载 作者:行者123 更新时间:2023-12-03 16:27:15 26 4
gpt4 key购买 nike

我想刷新 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];
}

但是这个功能也不起作用。

谁能帮帮我吗?

最佳答案

executeAndReturnError: 调用之后,您检查过 err 字典的值吗?

正确的 AppleScript 语法是:

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

编辑添加:或者,您可以下拉到 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;
}

关于objective-c - 如何刷新取景器窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8892246/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com