Re: Reveal in Finder Sample Code
Re: Reveal in Finder Sample Code
- Subject: Re: Reveal in Finder Sample Code
- From: Greg Robbins <email@hidden>
- Date: Thu, 13 Jan 2005 16:32:02 -0800
At 1:13 PM +1300 1/14/05, Henry Maddocks wrote:
[[NSWorkspace sharedWorkspace] selectFile:path
inFileViewerRootedAtPath:nil];
On 14/01/2005, at 1:05 PM, Michael Briscoe wrote:
Does anybody know how to implement a, "Reveal in Finder", feature
like that in Xcode and other applications.
The NSWorkspace method displays a browser window. The generic
approach uses an Apple event sent to the Finder:
OSErr RevealItemInFinder(const FSRef* pItemRef)
{
OSErr err;
AEAddressDesc targetAddrDesc = { typeNull, nil };
AppleEvent theAppleEvent = { typeNull, nil };
AppleEvent replyAppleEvent = { typeNull, nil };
AliasHandle alias = nil;
OSType finderSig = 'MACS';
err = FSNewAlias(nil, pItemRef, &alias);
require_noerr(err, Bail);
HLock((Handle) alias); // HLock is unneeded on Mac OS X
// address target by signature
err = AECreateDesc(typeApplSignature, &finderSig,
sizeof(OSType), &targetAddrDesc);
require_noerr(err, Bail);
// make the event
err = AECreateAppleEvent(kAEMiscStandards,
kAEMakeObjectsVisible, &targetAddrDesc, kAutoGenerateReturnID,
kAnyTransactionID, &theAppleEvent);
require_noerr(err, Bail);
err = AEPutParamPtr(&theAppleEvent, keyDirectObject,
typeAlias, *alias, GetHandleSize((Handle) alias));
require_noerr(err, Bail);
// send it
err = AESend(&theAppleEvent, &replyAppleEvent, kAENoReply,
kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
// bring the finder forward
ProcessSerialNumber finderPSN;
GetPSNFromSignature(finderSig, &finderPSN); // this calls
GetNextProcess until GetProcessInformation finds the serial number of
the app with the given signature
SetFrontProcess(&finderPSN);
Bail:
if (alias) DisposeHandle((Handle) alias);
if (targetAddrDesc.dataHandle) AEDisposeDesc(&targetAddrDesc);
if (theAppleEvent.dataHandle) AEDisposeDesc(&theAppleEvent);
return err;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden