?
Solved

How do I get Finder to recognize new custom icon?

Posted on 1997-02-26
10
Medium Priority
?
270 Views
Last Modified: 2013-12-26
I've got an application that sets up the custom icon resources. It looks like the resources are getting put in the right places and other applications can see that they are there.

One problem: the Finder doesn't update the display of the file. I'm guessing that there is some kind of caching mechanism that is preventing the update. I tried twiddling the modification dates of the files and using ResEdit to flip some of the Finder flags, but nothing seems to work.

Anybody out there have any clues or code snippets?

Thanks in advance,

Craig Hockenberry
0
Comment
Question by:craigh022697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Expert Comment

by:tristero
ID: 1291387
One trick you need to be aware of is that the caching is based on the FOLDER that the file lives in.  You should try changing the modification date of the directory that contains the file.  Be careful to only change the mod date (ie, read the original details, then change the mod date, then write them back).

This usually works, although if you are trying to change standard icons in an application, it usually takes a desktop rebuild.
0
 

Author Comment

by:craigh022697
ID: 1291388
No, this won't work (at least on my 7.5.5 system). I'm trying to add _custom_ icons (not standard icons .. there are no BNDL issues). I've found that I need to send the Finder some AppleEvents and let it set the custom icon through it's normal mechanism (via the cache). I'm not sure what the correct AppleEvents are though...
0
 

Expert Comment

by:tristero
ID: 1291389
Hmmm.  I was not talking about custom icons specifically.  Any change you make to a folder usually needed to have the folder touched.

Perhaps what you are thinking of is the 'fupd' event.  I am not sure whether the direct object needs to be the file or the enclosing folder.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:craigh022697
ID: 1291390

0
 

Author Comment

by:craigh022697
ID: 1291391
Hit the submit button on the previous one before I typed anything.

Here's what I'm doing...

The following code is distilled from Greg Anderson's article in Develop #10:

      osErr = GetFinder (&finderPSN);
      osErr = AECreateDesc(typeProcessSerialNumber, &finderPSN, sizeof(ProcessSerialNumber), &target);
      osErr = AECreateAppleEvent(kAECoreSuite, kAEGetData, &target, kAutoGenerateReturnID, kAnyTransactionID, &ae);

#ifdef IT_WORKS      
      osErr = AECreateDesc(typeType, &selectionProperty, sizeof(DescType), &specDesc);
      osErr = CreateObjSpecifier(cProperty, &nullDesc, formPropertyID, &specDesc, false, &specifier); // TEMPORARY - disposeInputs parameter should be true
      osErr = AECreateDesc(typeType, &iconProperty, sizeof(DescType), &keyData);
      osErr = CreateObjSpecifier(cProperty, &specifier, formPropertyID, &keyData, false, &directSpecifier); // TEMPORARY - disposeInputs parameter should be true
      
      osErr = AEPutParamDesc(&ae, keyDirectObject, &directSpecifier);

#else // IT DOESN'T WORK

      osErr = AECreateDesc(typeFSS, file, sizeof(FSSpec), &specDesc);
      osErr = CreateObjSpecifier(cItem, &nullDesc, formPropertyID, &specDesc, false, &specifier); // TEMPORARY - disposeInputs parameter should be true
      osErr = AECreateDesc(typeType, &iconProperty, sizeof(DescType), &keyData);
      osErr = CreateObjSpecifier(cProperty, &specifier, formPropertyID, &keyData, false, &directSpecifier); // TEMPORARY - disposeInputs parameter should be true
      
      osErr = AEPutParamDesc(&ae, keyDirectObject, &directSpecifier);
#endif      

      osErr = AESend(&ae, &aeReply, kAEWaitReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL); // TEMPORARY - (kAENoReply |  kAENeverInteract)
      
      osErr = AEGetParamDesc(&aeReply, keyAEResult, typeWildCard, &result);

The code from the article shows how to change the icon of the current Finder selection. I want to use a FSSpec instead of the object specifier (he says you can do that in the article). I haven't been able to get this to work (and I've tried _many_ different combinations).

I'm also aware of the 'fupd' event. I've not been successful with that either (from a folder or a file):

      osErr = GetFinder (&finderPSN);
      osErr = AECreateDesc(typeProcessSerialNumber, &finderPSN, sizeof(ProcessSerialNumber), &target);
      osErr = AECreateAppleEvent(kAEFinderSuite, kAEUpdate, &target, kAutoGenerateReturnID, kAnyTransactionID, &ae);
      
      osErr = AECreateDesc(typeFSS, file, sizeof(FSSpec), &specDesc);
      osErr = AEPutParamDesc(&ae, keyDirectObject, &specDesc);

      osErr = AESend(&ae, &aeReply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL); // TEMPORARY - (kAENoReply |  kAENeverInteract)

This Apple Events stuff is really hairy... I've read shitloads of documentation and I still don't have a solid grasp of the concepts. And I thought the ScriptEditor was a pain in the ass...

0
 
LVL 1

Expert Comment

by:irac
ID: 1291392
Don't know if this will help but I found it while surfing around looking for applescript information.  You could send similar  events to the finder to get it to change the icon of said thing.

This is from:
http://devworld.apple.com/ngs/lpp/adrpub/docs/dev/techsupport/develop/issue20/20anderson.html

GETTING AND SETTING CUSTOM ICONS

The icon bitmap of a file is available through ordinary file system calls, but there are a couple of
different cases to contend with: the icon might be stored in the desktop database, or it could be a custom
icon stored in the resource fork of the file. Some files are "special," and only the Finder really knows what
their icon bitmap should be. The simplest way to get the exact icon bitmap for a file is to ask the Finder
what it is. Once again, Get Data and Set Data are the events to use.

The result of a Get Data event that specifies the icon property of some object is an AERecord that
contains the entire icon family for the item's icon. The record contains parameters whose key is the same
as the individual resources of an icon family (for example, 'ICN#' and 'icl8'); the data stored in these
parameters is identical to the data found in a resource of the same type. A Set Data event takes a record
in the same format, or an empty list if the intention is to remove the custom icon.

Listing 4 shows how to remove the custom icon from every item in the selection. Note that the specifier
"icon of selection" is equivalent to the more complex specifier "icon of every item of selection."

Listing 4 shows how to remove the custom icon from every item in the selection. Note that the specifier
"icon of selection" is equivalent to the more complex specifier "icon of every item of selection."

Listing 4. Removing custom icons from the selection

// tell application "Finder"
//      set icon of selection to empty
// end tell
TAEvent   ae;

TDescriptor target = GetAddressOfFinder();
ae.MakeAppleEvent(kAECoreSuite, kAESetData, target);
target.Dispose();

// Make an object specifier for "icon of selection" and put it into the
// direct object of the event.
TDescriptor directObjectSpecifier;
TDescriptor selectionSpecifier;
TDescriptor keyData;
TDescriptor nullDescriptor;

keyData.MakeDescType(pSelection);
selectionSpecifier.MakeObjectSpecifier(cProperty, nullDescriptor,
   formPropertyID, keyData, true);
keyData.MakeDescType(pIconBitmap);
directObjectSpecifier.MakeObjectSpecifier(cProperty, selectionSpecifier,
   formPropertyID, keyData, true);
ae.PutDescriptor(keyDirectObject, directObjectSpecifier);
directObjectSpecifier.Dispose();

// Obviously, a Set Data event needs data. In the case of this sample,
// the data we want is "empty," which is represented by an empty list.
TDescriptor emptyList;

emptyList.MakeEmptyList();
ae.PutDescriptor(keyAEData, emptyList);
emptyList.Dispose();

// Send the event and dispose of it once it has been sent.
TAEvent   reply;

ae.Send(&reply, kAENoReply);
ae.Dispose();

The sample application Finder Tricks on the CD has a feature that changes the icons of all the items in the
frontmost Finder window -- each item is given some other item's icon. Other than serving as a useful
example of how to send events to the Finder, this sample doesn't have much utility, although it does do an
admirable job at messing up the appearance of Finder windows.

An application can change an item's icon by writing the custom icon directly into the appropriate resources
in the file and then setting the "custom icon bit" using the file system, instead of sending an event to the
Finder -- but the change won't take effect right away. The reason for the delay is that the Finder isn't
notified when the contents of the disk change, so it must periodically poll the file system to find out
whether it needs to redraw any items in its open windows. Polling happens only every now and again, so that
the Finder doesn't eat up every spare CPU cycle on the machine when it's just sitting idle in the
background.
0
 

Author Comment

by:craigh022697
ID: 1291393
This code is the same as the code from the Develop article. I understand this code .. the problem is that I haven't been successful at changing the selection property (the currently selected item on the finder desktop) to a file specified by my application (a FSSpec).

I've gotten some hints from the author of the article and am trying them out now.
0
 

Expert Comment

by:raine
ID: 1291394
This may sound basic, but are you restting the "inited" bit in the finder flags ?

localError := FSPGetFInfo(localSpec, localInfo);
if localError = noErr then
  if BAND(localInfo.fdFlags,kHasBeenInited) <> 0 then
    begin
      localInfo.fdFlags := localInfo.fdFlags - kHasBeenInited;
     localError := FSPSetFInfo(lcoalSpec,localInfo);
    end;

and as correctly pointed out in the comments, you then need to change the modification date of the enclosing folder to force the finder to notice it.


    end;
0
 

Author Comment

by:craigh022697
ID: 1291395

0
 
LVL 1

Accepted Solution

by:
atlas earned 100 total points
ID: 1291396
the following snippet is what I use to force the Finder to update. It does this by changing the modification date of the parent ID of the file, the Finder will now update the contents.
Pass this routine an FSSpec to the file to be updated.


void ForceFinderUpdate(FSSpecPtr myFSSPtr)
{
      OSErr                  lErr;
      CInfoPBRec            lCBlk;
      
      
      if (myFSSPtr->parID != 1)                                          
            lCBlk.dirInfo.ioNamePtr = 0L;
            lCBlk.dirInfo.ioVRefNum = myFSSPtr->vRefNum;            
            lCBlk.dirInfo.ioDrDirID = myFSSPtr->parID;
            lCBlk.dirInfo.ioFDirIndex = 0;
            lCBlk.dirInfo.ioCompletion = 0;      
            lErr = PBGetCatInfo(&lCBlk, FALSE);
            GetDateTime(&lCBlk.dirInfo.ioDrMdDat);
            lCBlk.dirInfo.ioDrDirID = myFSSPtr->parID;
            lErr = PBSetCatInfo(&lCBlk, FALSE);
            lErr = FlushVol(nil, myFSSPtr->vRefNum);

}
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question