• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how to change folder attributes from postinstall (missing SetFile?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to change folder attributes from postinstall (missing SetFile?)


  • Subject: Re: how to change folder attributes from postinstall (missing SetFile?)
  • From: Mario Emmenlauer <email@hidden>
  • Date: Mon, 27 Oct 2008 14:35:30 +0100


Hi,

Iceberg-Dev wrote:
On Oct 23, 2008, at 7:01 PM, Mario Emmenlauer wrote:
I have an installer that works very well as long as I have 'Include
Root in Package' enabled. When I disable it, the Icons for the app-
lication bundle don't show up until the user reboots.

The reason seems that PackageMaker creates the root folder (instead of
unpacking it), and therefore the folder lacks attributes?!


Using 'SetFile -a C /Applications/Folder.app' from a postinstall-script, I can make the Icons appear. However, SetFile is not available on the users machines.

Whats the right tool to use on a users machine to set folder attributes?

It's pretty easy to write one, you only need to play with the FSCatalogInfo data.


You can get a good starting with the code available at this URL:

http://homepage.mac.com/jrc/contrib/tools/SetInvisible.c


Your hint was actually very good, I changed a few lines of code
and will now really distribute the little program with my installer.
I have attached it, in case somebody can use a SetCustomIcon-cmdline-
prog.

Compile: gcc -o SetCustomIcon -framework CoreServices SetCustomIcon.c

Note that for the sole purpose of having Finder refresh the icons,
a simple 'touch' of the containing folder is sufficient. But for
changing the Attribute you need SetFile of the little helper here.


Cheers,

Mario
/*
 *  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 invisibility bit of a file/folder.
 *  -v means make visible, -V means make invisible.
 *
 */
#include <CoreServices/CoreServices.h>

#include <unistd.h> // getopt
#include <stdlib.h> // realpath


int main (int argc, const char * argv[]) {
	// Parse command-line arguments
  if (argc != 2) {
    printf("Please provide a path to a file/folder.\n");
    return 1;
  }

	// Resolve specified path
	char* path = (char *)argv[1];
	char* resolved_path = (char*)malloc(PATH_MAX);
	if (realpath(path, resolved_path) == NULL) {
    free(resolved_path);
    printf("Could not resolve path '%s'\n", path);
    return 1;
  }


	// Set the visibility
	FSRef ref;
	OSStatus status = FSPathMakeRef((unsigned char*)resolved_path, &ref, NULL);
  free(resolved_path);
	if (status != noErr) {
		printf("FSPathMakeRef failed\n");
    return 1;
  }

  // Prepare to get the Finder info.
	FSCatalogInfoBitmap whichInfo = kFSCatInfoFinderInfo;
	FSCatalogInfo catalogInfo;

  // Now we need to set the file's Finder info so the Finder will know that
  // it has a custom icon.  Start by getting the file's current finder info:
	status = FSGetCatalogInfo(&ref, whichInfo, &catalogInfo, /*outName*/ NULL, /*fsSpec*/ NULL, /*parentRef*/ NULL);
	if (status != noErr) {
		printf("FSGetCatalogInfo failed\n");
    return 1;
  }

  FileInfo * finderInfo = (FileInfo *)&catalogInfo.finderInfo;
  //if (mode == 'v')
  //	finderInfo->finderFlags &= ~kIsInvisible;	// clear bit
  //else
  //	finderInfo->finderFlags |= kIsInvisible;	// set bit


  // Set the kHasCustomIcon flag, and clear the kHasBeenInited flag.
  //
  // From Apple's "CustomIcon" code sample:
  //     "set bit 10 (has custom icon) and unset the inited flag
  //      kHasBeenInited is 0x0100 so the mask will be 0xFEFF:"
  //    finderInfo.fdFlags = 0xFEFF & (finderInfo.fdFlags | kHasCustomIcon ) ;
  finderInfo->finderFlags = (finderInfo->finderFlags | kHasCustomIcon ) & ~kHasBeenInited;


  status = FSSetCatalogInfo(&ref, whichInfo, &catalogInfo);
  if (status != noErr) {
    printf("FSSetCatalogInfo failed\n");
    return 1;
  }

  return 0;
}
 _______________________________________________
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

References: 
 >how to change folder attributes from postinstall (missing SetFile?) (From: Mario Emmenlauer <email@hidden>)
 >Re: how to change folder attributes from postinstall (missing SetFile?) (From: Iceberg-Dev <email@hidden>)

  • Prev by Date: Re: how to change folder attributes from postinstall (missing SetFile?)
  • Next by Date: Re: how to change folder attributes from postinstall (missing SetFile?)
  • Previous by thread: Re: how to change folder attributes from postinstall (missing SetFile?)
  • Next by thread: [JavaScript] Another requirement bug
  • Index(es):
    • Date
    • Thread