• 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: Reveal in Finder Sample Code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Reveal in Finder Sample Code
      • From: Evan Schoenberg <email@hidden>
References: 
 >Reveal in Finder Sample Code (From: Michael Briscoe <email@hidden>)
 >Re: Reveal in Finder Sample Code (From: Henry Maddocks <email@hidden>)

  • Prev by Date: [Moderator] "RFC" -- Specialist lists (was Re: Bindings Book !!!!!)
  • Next by Date: Re: Reveal in Finder Sample Code
  • Previous by thread: Re: Reveal in Finder Sample Code
  • Next by thread: Re: Reveal in Finder Sample Code
  • Index(es):
    • Date
    • Thread