1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

App icon data location (when pasted in)

Discussion in 'Mac Programming' started by Let's Sekuhara!, Jul 1, 2012.

  1. macrumors 6502

    Let's Sekuhara!

    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?
  2. macrumors 603

    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.
  3. macrumors 6502

    Let's Sekuhara!

    Thank you for the very helpful and descriptive answer! :)
  4. macrumors 6502

    Let's Sekuhara!

    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?

    $ 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.
  5. macrumors 603

    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?
  6. macrumors 6502

    Let's Sekuhara!

    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.

    You're absolutely right. The results are as follows:
    (Made a copy of Dashboard as a test)
    $ 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:
    $ ls Dashboard2.app
    Contents	Icon?
    And if I Tab to autocomplete the filename it autocompletes as:
    I don't understand why it has three names to refer to the same file. (Icon, Icon?, Icon^M)
    But that's ok.

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

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

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

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

    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.
  7. macrumors 603

    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.
  8. macrumors 68000


    So the icon file is in the app's root directory?

Share This Page