Skip to content

Instantly share code, notes, and snippets.

@fabiofl
Created June 27, 2013 00:41
Show Gist options
  • Save fabiofl/5873100 to your computer and use it in GitHub Desktop.
Save fabiofl/5873100 to your computer and use it in GitHub Desktop.
Clear Mac OS X's icon cache.
sudo find /private/var/folders/ -name com.apple.dock.iconcache -exec rm {} \;
@andreiborisov
Copy link

So are you also seeing these Icon\r files as zero bytes after dragging?

No, they have non-zero size for me. Does an icon for the app changes with the dragging method for you when the size of Icon\r is zero?

@andreiborisov
Copy link

It signals some undocumented black magic voodoo. That's why I'm basically 100% out on this method.

I mean it is all undocumented black magic, unfortunately. Why touching an app bundle refreshes cache for example? Why it works for one app, but not for the other? More importantly, how can we sure it won’t break in the next macOS release? At least with Icon\r method there is some level of confidence it won’t change the behavior between macOS versions simply because it’s part of the filesystem and it’s required to be backwards compatible.

But I see your point of course.

@jasonm23
Copy link

So are you also seeing these Icon\r files as zero bytes after dragging?

No, they have non-zero size for me. Does an icon for the app changes with the dragging method for you when the size of Icon\r is zero?

That's right, but I'm several hours away from the last live test. It's something I can check again in the morning.

@andreiborisov
Copy link

andreiborisov commented Aug 27, 2020

Ok, that's even more interesting😂

CleanShot 2020-08-27 at 19 08 35@2x

yet

CleanShot 2020-08-27 at 19 09 00@2x

Sorry, I didn't try to check the size from shell before, I have no idea why it's reported as 0 there, but in reality, it has size as you can see...

@jasonm23
Copy link

jasonm23 commented Aug 27, 2020

"in reality..." Uhmmm.

Tbh in reality all we know is that Finder's internal logic has embedded the icon somewhere. The trouble is, where. We know it's not really in that file Icon\r because the actual file system doesn't register the file size.

The worst problem here is that neither representation is "in reality". They're both views through different abstraction layers, but it's safe to say only that those icon data bytes went "somewhere". Unfortunately that doesn't give us a thing to stand on.

All completely undocumented. All completely unreliable.

If you can script it somehow and make it reliable, applause for you.

@frakman1
Copy link

frakman1 commented Dec 1, 2020

On High Sierra, deleting com.apple.dock.plist worked for me. However, a couple of native apps stubbornly refused to work. The Notes and Screen Sharing apps still have the default app icon.

Update:
I fixed those apps by removing them from the dock and then re-adding them. It worked after that.

@beginnerJq
Copy link

@jasonm23 thanks

@jkrovitz
Copy link

jkrovitz commented Nov 7, 2021

sudo rm -rfv /Library/Caches/com.apple.iconservices.store; sudo find /private/var/folders/ \( -name com.apple.dock.iconcache -or -name com.apple.iconservices \) -exec rm -rfv {} \; ; sleep 3;sudo touch /Applications/* ; killall Dock; killall Finder

after that restart your mac.

wahlaaah.. all restore and back to normal

This worked really well! Thank you @zigang93.

@tobiashochguertel
Copy link

tobiashochguertel commented May 6, 2022

sudo rm -rfv /Library/Caches/com.apple.iconservices.store; sudo find /private/var/folders/ \( -name com.apple.dock.iconcache -or -name com.apple.iconservices \) -exec rm -rfv {} \; ; sleep 3;sudo touch /Applications/* ; killall Dock; killall Finder
after that restart your mac.
wahlaaah.. all restore and back to normal

This worked really well! Thank you @zigang93.

Works!

Here for better readable and discovering the shell-snippet again:

sudo rm -rfv /Library/Caches/com.apple.iconservices.store; sudo find /private/var/folders/ \( -name com.apple.dock.iconcache -or -name com.apple.iconservices \) -exec rm -rfv {} \; ; sleep 3;sudo touch /Applications/* ; killall Dock; killall Finder

@jbrodriguez
Copy link

@jasonm23 @andreiborisov i'm interested in changing icons via cli, doing some more debugging, found these articles:

The first one clarifies the 0 bytes size of Icon\r: the file is actually stored in the resource fork

@jbrodriguez
Copy link

jbrodriguez commented May 7, 2022

and finally this tool looks promising (although i haven't tested it myself) https://github.com/mklement0/fileicon

EDIT: i tried the tool and it works for me on Monterrey, although i still need to rebuild the cache and restart dock:

rm /var/folders/*/*/*/com.apple.dock.iconcache
killall Dock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment