1

I am using setIcon:forFile:options: method of NSWorkspace class for setting custom icon for file and directory. My problem is that , the Finder is not reflecting icon change in icon view until restart.

Icon view:
enter image description here

enter image description here

List view (outline view):
enter image description here

Parag Bafna
  • 22,812
  • 8
  • 71
  • 144

1 Answers1

1

From Carbon development tips and tricks .

You need to send a kAESync AppleEvent to the Finder passing it an alias to the file that was changed.

Below code is written by JWWalker

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;
}
Community
  • 1
  • 1
Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
  • Is this similar to calling NSWorkspace's `noteFileSystemChanged:` method? – radj Jan 26 '17 at 09:02
  • Intermittently, it fails. Maybe I should try this sequence instead. PS, I can't seem to @mention you. – radj Jan 27 '17 at 07:11
  • 1
    @radj Have a look at http://stackoverflow.com/questions/11781373/finder-update-refresh-applescript-not-working-in-10-8 – Parag Bafna Jan 27 '17 at 07:33