[英]How to refresh finder window?
I want to refresh icon for particular file/folder in Finder application. 我想刷新Finder应用程序中特定文件/文件夹的图标。
FNNotifyByPath( (const UInt8 *)folderPath, kFNDirectoryModifiedMessage, kNilOptions );
FNNotifyByPath
is not working for this. FNNotifyByPath
不适用于此目的。 Now i am trying with appleScript 现在我正在尝试使用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? 有人可以帮我吗?
Did you check the value of the err
dictionary after the executeAndReturnError:
call? 在
executeAndReturnError:
调用之后,您是否检查了err
词典的值?
The correct AppleScript syntax would be: 正确的AppleScript语法为:
@"tell application \\"Finder\\" to update POSIX file \\"%@\\""
@“告诉应用程序\\” Finder \\“更新POSIX文件\\”%@ \\“”
EDIT TO ADD: Alternately, you could drop down to the AppleEvent level: 编辑添加:或者,您可以下降到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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.