• Hello MLAers! We've re-enabled auto-approval for accounts. If you are still waiting on account approval, please check this thread for more information.

Quiting the Finder

Hi!

In my new program I need to make the Finder quit. How do I do that?

I could use a high-level event (or is it an Apple Event?) to do it, but I don't know what codes to use.

Any help would be appreciated.

Thanks

onlyonemac

 
There used to be a shareware program called System 7 Pack that would allow one to add this option to Finder 7. The program is written by Adam Stein.

 
There was WizTools as well... can't seem to find that one.

But anyway what I mean is that I'm writing a program and, in part of the code, I need to tell the Finder to quit and reopen itself. How?

 
I can't say I'm a programming expert, but maybe some of these ideas would be of help:

1. If you force quit the Finder with the escape key combination, it will always open right back up. It's not like other programs where force quitting will simply terminate it. Perhaps a way to invoke that would work, although you'd still have to get around the pesky dialog box.

2. I'm not sure if Adam Stein is still around, but perhaps he'd have a contact somewhere. Since he wrote a program to actually quit the Finder and make it stay closed, he may have some insight on this subject. I'd imagine there's a challenge in getting around the Finder reopening since it seems to do this by default. System 7 was designed this way.

3. On Mac OS 9, if the Finder crashes, it re-opens. More proof that you simply need a way to get the Finder to quit to have it reopen.

Keep me posted on this--I'm interested to see how it turns out.

 
Hi,

In the distant past (7+ years ago), I played around with replacing the Finder executable in the System Folder with another application by fooling the OS into thinking the application was the Finder.

I did this simply by changing the type and creator codes of said application to those of the Finder. The only downside to this approach is that the regular Finder is permanently disabled, rendering the OS useless if the replacement application doesn't work (and you can forget about file management, unless the application has some built-in facilities for doing such things).

I hope this helps!

c

 
^ Uhh, no. That's not what I'm trying to do.

Essentialy, I'm trying to close the Finder from my program (without user interaction) and then let it reopen itself. (I'm quite sure it's got something to do with sending it some sort of high-level event, but Inside Macintosh does not give a table of said events).

 
Send the finder the quit apple event? You can do it by executing a script, or you can just build the event procedurally and send it.

 
Here is an outline for making and sending a quit apple event to the finder. I haven't tried to compile or execute this, and it may have errors, but it is the basic outline. Executing a script in a file is about the same amount of code.

Here is the function that will quit the finder

OSErr quitFinder(void)

{

ProcessSerialNumber psn;

AppleEvent theQuitEvent;

OSErr result;

//1. get the process id of the program you want to quit, using the finder's type and creator. return result in psn

result=FindAProcess('FNDR','MACS',&psn);

if (result==noErr)

{

//2. make the apple event using the psn. return the result in theQuitEvent

result=MakeQuitEvent(&theQuitEvent,psn);

if (result==noErr)

{

//3. send the event.

result=sendQuitEvent(&theQuitEvent)

}

else

return result;

}

else

return result;

}

Here are the three functions

// FindAProcess-- checks all running processes to see if there is one running that uses

// the type and creator we are looking for. processSN is returned

OSErr FindAProcess(OSType typeToFind, OSType creatorToFind,

ProcessSerialNumberPtr processSN)

{

ProcessInfoRec tempInfo;

FSSpec procSpec;

Str31 processName;

OSErr myErr = noErr;

/* nul out the PSN so we're starting at the beginning of the list */

processSN->lowLongOfPSN = kNoProcess;

processSN->highLongOfPSN = kNoProcess;

/* initialize the process information record */

tempInfo.processInfoLength = sizeof(ProcessInfoRec);

tempInfo.processName = processName;

tempInfo.processAppSpec = &procSpec;

/* loop through all the processes until we */

/* 1) find the process we want */

/* 2) error out because of some reason (usually, no more processes */

do {

myErr = GetNextProcess(processSN);

if (myErr == noErr)

GetProcessInformation(processSN, &tempInfo);

}while ((tempInfo.processSignature != creatorToFind ||

tempInfo.processType != typeToFind) ||

myErr != noErr);

return(myErr);

}

You also need to make an event. This one will create your appleevent and

return it in the container you pass in as theAppleEvent. It needs to know

the process serial number of the program you want to quit

OSErr MakeQuitEvent(AppleEvent* theAppleEvent,ProcessSerialNumber psn)

{

OSErr myErr;

AEDescList fileAliasListDesc;

AEAddressDesc targetAddress;

OSErr ignoreErr;

myErr=AECreateDesc(typeProcessSerialNumber, &psn,

sizeof(ProcessSerialNumber),&targetAddress);

if (myErr!=noErr)

{

doError("Making Target Descriptor for Program to Quit",myErr);

return(myErr);

}

myErr = AECreateAppleEvent(kCoreEventClass, kAEQuit,

&targetAddress, kAutoGenerateReturnID,

kAnyTransactionID, theAppleEvent);

if (myErr!=noErr)

{

doError("Creating the Quit Event",myErr);

ignoreErr=AEDisposeDesc(&targetAddress);

return(myErr);

}

return(noErr);

}

OSErr sendQuitEvent(AppleEvent *theQuitEvent)

{

OSErr myErr;

AppleEvent reply;

myErr=AESend(&theAppleEvent, &reply, kAENoReply + kAENeverInteract,

kAENormalPriority, 240, nil, nil);

if (myErr!=noErr) /*Apple event successfully sent*/

doError("Sending the Quit Event",myErr);

return myErr;

}

 
Back
Top