Re: Is setting a custom folder icon possible?
site_archiver@lists.apple.com Delivered-To: installer-dev@lists.apple.com On mardi, mai 17, 2005, at 12:39 PM, Mike Fischer wrote: Hi, Yes. 2 solutions: 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<------- -------8<-------8<-------8<-------8<------- #!/bin/sh exit 0 -------8<-------8<-------8<-------8<------- #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); 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; } 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 (Installer-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/installer-dev/site_archiver%40lists.a... 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? o you're 100% sure the target machine and OS has the Developer Tools installed: 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: "$1/Contents/Resources/setHasCustomIcon" -C "/Applications/Adobe Photoshop 7" 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> // 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"); -------------8<------------8<------------8<------------8<------------ 8<------------ This email sent to site_archiver@lists.apple.com
participants (1)
-
Stéphane Sudre