Re: Is setting a custom folder icon possible?
Re: Is setting a custom folder icon possible?
- Subject: Re: Is setting a custom folder icon possible?
- From: Stéphane Sudre <email@hidden>
- Date: Tue, 17 May 2005 13:47:41 -0700
On mardi, mai 17, 2005, at 12:39 PM, Mike Fischer wrote:
Hi,
I have (well, actually a friend of mine who is not on this list has)
been trying to get a Mac OS X installer package to install a folder
with a custom icon.
So far it looks like the Icon\n file is correctly installed (including
the resource fork which holds the icon data) but the custom icon
Finder flag is not set on the enclosing folder. (As evidenced by
/Developer/Tools/GetFileInfo -a <path to folder>. The "c" is lowercase
indicating the flag not set.)
Is it possible to set a custom folder icon using installer packages?
If so, how?
Yes.
2 solutions:
o you're 100% sure the target machine and OS has the Developer Tools
installed:
Add a postflight script like this:
-------8<-------8<-------8<-------8<-------
#!/bin/sh
/Developer/Tools/SetFile -a C "/Applications/Adobe Photoshop 7"
exit 0
-------8<-------8<-------8<-------8<-------
o you're not 100% sure the target machine will have the Developer Tools
installed:
Keep the same scenario as above but instead of using the
/Developer/Tools/SetFile tool, you will need to use your own. Add the
tool to the Resources and in the postflight script call it with:
-------8<-------8<-------8<-------8<-------
#!/bin/sh
"$1/Contents/Resources/setHasCustomIcon" -C "/Applications/Adobe
Photoshop 7"
exit 0
-------8<-------8<-------8<-------8<-------
Here is some source code inspired from a tool made by a "Swedish"
developer:
-------------8<------------8<------------8<------------8<------------
8<------------
/*
* SetHasCustomIcon.c
* based on SetInvisible.c created by John R Chang on Wed May 26 2004.
* This code is Creative Commons Public Domain. You may use it for
any purpose whatsoever.
* http://creativecommons.org/licenses/publicdomain/
*
* Sets the Finder customIcon bit of a file/folder.
* -c means no custom icon, -C means use a custom icon.
*
*/
#include <CoreServices/CoreServices.h>
#include <unistd.h> // getopt
#include <stdlib.h> // realpath
#include <err.h>
static void usage()
{
fprintf(stderr, "usage: (-c|-C) <path>\n");
exit(1);
}
int main (int argc, const char * argv[]) {
// Parse command-line arguments
char mode = ' ';
int ch;
while ((ch = getopt(argc, (char * const *)argv, "cC")) != -1)
switch (ch) {
case 'c':
case 'C':
mode = ch;
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if (mode == ' ')
usage();
// Resolve specified path
char * path = (char *)argv[argc-1];
char resolved_path[PATH_MAX];
if (realpath(path, resolved_path) == NULL)
err(1, NULL);
// Set the visibility
FSRef ref;
OSStatus status = FSPathMakeRef(resolved_path, &ref, NULL);
if (status != noErr)
err(status, "FSPathMakeRef failed");
FSCatalogInfoBitmap whichInfo = kFSCatInfoFinderInfo;
FSCatalogInfo catalogInfo;
status = FSGetCatalogInfo(&ref, whichInfo, &catalogInfo, NULL, NULL,
NULL);
if (status != noErr)
err(status, "FSGetCatalogInfo failed");
FolderInfo * finderInfo = (FolderInfo *)&catalogInfo.finderInfo;
if (mode == 'c')
finderInfo->finderFlags &= ~kHasCustomIcon; // clear bit
else
finderInfo->finderFlags |= kHasCustomIcon; // set bit
status = FSSetCatalogInfo(&ref, whichInfo, &catalogInfo);
if (status != noErr)
err(status, "FSSetCatalogInfo failed");
return 0;
}
-------------8<------------8<------------8<------------8<------------
8<------------
You would need to create a new CoreServices tool.
Warning I didn't test the code, I just checked it was compiling.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Installer-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden