Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Let's Sekuhara!

macrumors 6502
Original poster
Jun 30, 2008
357
1
日本
OK, so you know how you can Get Info on a file such as an app and in the icon area of the info window paste in another icon to replace the existing one?

Where does that pasted-in icon data get stored?
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,425
A sea of green
For files, it's stored as a resource, in the resource fork of the file.

For directories (which have no resource-fork), it's stored in a ".Icon\r" file located in the folder. Since a .app "file" is actually a directory, a custom icon for an app is stored that way.

For disk volumes (which also have no resource-fork), it's stored in a ".VolumeIcon.icns" file at the root of the volume.
 

Let's Sekuhara!

macrumors 6502
Original poster
Jun 30, 2008
357
1
日本
For files, it's stored as a resource, in the resource fork of the file.

For directories (which have no resource-fork), it's stored in a ".Icon\r" file located in the folder. Since a .app "file" is actually a directory, a custom icon for an app is stored that way.

For disk volumes (which also have no resource-fork), it's stored in a ".VolumeIcon.icns" file at the root of the volume.

Thank you for the very helpful and descriptive answer! :)
 

Let's Sekuhara!

macrumors 6502
Original poster
Jun 30, 2008
357
1
日本
One more question on the subject of icon file paths... Would you happen to know why it is that even though this command replaces the icon file correctly, the app still doesn't show the right icon?

Code:
$ cp Source.app/Contents/Resources/*.icns Target.app/Contents/Resources/AutomatorApplet.icns
Try making test copies of two of your apps and try the command to see what I mean.
In my case my target app was made in Automator - that's why the file path is like that.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,425
A sea of green
That cp command isn't doing what you originally posted. You originally said "pasted-in icon data". What your cp is doing is replacing the original icon completely. That's completely different.

To see what "pasted-in icon data" actually does, do a before and after comparison of the complete contents of the app-bundle. Please post what happens. I suspect you'll NOT see it replace the internal .icns files.

As to the new issue, it's because LaunchServices caches the icons of an app. It won't refresh its cache unless the top-level app-bundle directory has a different modification date. See the 'touch' command.

Even with a touch, I'm not completely certain LS will update its cache. I've seen it malfunction before, but it sorta depended on OS version. Which version are you using?
 

Let's Sekuhara!

macrumors 6502
Original poster
Jun 30, 2008
357
1
日本
That cp command isn't doing what you originally posted. You originally said "pasted-in icon data". What your cp is doing is replacing the original icon completely. That's completely different.
Ah, yes. I realize that. I should have specified that I don't particularly care by which method the icon gets replaced. I've been trying different approaches.

To see what "pasted-in icon data" actually does, do a before and after comparison of the complete contents of the app-bundle. Please post what happens. I suspect you'll NOT see it replace the internal .icns files.
You're absolutely right. The results are as follows:
(Made a copy of Dashboard as a test)
Code:
$ diff Dashboard.app Dashboard2.app
Common subdirectories: Dashboard.app/Contents and Dashboard2.app/Contents
Only in Dashboard2.app: Icon

If I list the contents of my altered copy of the app:
Code:
$ ls Dashboard2.app
Contents	Icon?

And if I Tab to autocomplete the filename it autocompletes as:
Code:
Dashboard2.app/Icon^M

I don't understand why it has three names to refer to the same file. (Icon, Icon?, Icon^M)
But that's ok.

As to the new issue, it's because LaunchServices caches the icons of an app. It won't refresh its cache unless the top-level app-bundle directory has a different modification date. See the 'touch' command.

Thank you for the info. That's good to know.
My results using touch are as follows:

Code:
$ cp Dashboard2.app/Icon^M Dashboard3.app/
Copied the custom icon to yet another .app bundle.

Code:
$ ls Dashboard3.app
Contents	Icon?
Listed to make sure it was copied successfully.

Code:
$ touch Dashboard3.app
Touched it in hopes that LaunchServices would notice and refresh, but it did not.

Even with a touch, I'm not completely certain LS will update its cache. I've seen it malfunction before, but it sorta depended on OS version. Which version are you using?
10.6.8 on one machine and 10.7.4 on another.

Thank you for your help.
If any other ideas come to mind please let me know.
I'm off to scour teh Googles in hopes of finding out why LaunchServices may fail to acknowledge an Icon^M file.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,751
8,425
A sea of green
I don't understand why it has three names to refer to the same file. (Icon, Icon?, Icon^M)
But that's ok.

There's only one name. It's just being displayed by three different programs.

^M means control-M. Which is CR (Carriage Return). See any ASCII code table.

The program that only shows Icon is probably just outputting the string directly. Which would result in a CR being output. Which may have no consequences, or may simply add a blank line to the output.

The program that shows Icon? is probably a result of a Terminal setting that translates all non-displayables (which includes ctrl-chars) to '?'. You could name a file ESC-C (where ESC is the actual ASCII ESC character, 0x1B), and the ESC character would appear as '?' in Terminal. It's usually difficult to type such chars in Terminal, but not impossible.

The program showing Icon^M is clearly performing a translation of ctrl-chars to visible representation.

If you recall, my first reply said the icon was stored in ".Icon\r". I clearly misremembered the leading dot. However, the "\r" was absolutely intended to mean the ASCII CR characters, 0x0D, whose C-style escape is \r, and where the shell can also sometimes be induced to accept as \r.


Regarding the LS refresh. This is a long-standing issue. A few other tricks I've used in the past:

1. Archive the app into a zip file. Delete the original app. Unarchive.
2. Move the app to another folder (even a sub-folder), then move it back.
3. Copy the app to another volume (even a disk-image volume), delete original, then copy it back.

There are also LS functions/methods to tell LS that it should take note of changes to a particular app. Or that it should scan a directory for apps it should note.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.