Re: Finder Selection
Re: Finder Selection
- Subject: Re: Finder Selection
- From: Rosyna <email@hidden>
- Date: Tue, 25 Sep 2001 05:38:13 -0700
Well, being someone that actually GETS the finder selection (*looks
at Ondra*), I can give you first hand experience.
Your best bet for 10.0.4 is to use AppleScript to get it, however
there are grave limitations in this. (no unicode, no files ending in
.app, no files starting with ~). You can use carbon with the below
code, however it doesn't work in 10.0.x or 10.1. Ok, so it sort of
works in 10.1 but the Type returned is ALWAYS unicode text and it may
be malformed. I go with the AppleScript method.
#ifdef cracker
OSErr GetFinderSelection(AppleEvent* reply)
{
OSErr err=noErr;
AppleEvent ae;
DescType theType=pSelection,theOtherType=typeFileURL;
AEAddressDesc finderTarget=GetAddressOfFinder();
{
{
Handle xx;
AEPrintDescToHandle(&finderTarget,&xx);
CFStringRef
string=CFStringCreateWithFormat(NULL,NULL,CFSTR("Finder Target:
%s"),*xx);
CFShow(string);
if (string) CFRelease(string);
DisposeHandle(xx);
}
}
if (err) showError("\pCannot make Target",err);
err=AECreateAppleEvent(kAECoreSuite,kAEGetData,&finderTarget,
kAutoGenerateReturnID, kAnyTransactionID, &ae);
if (err) showError("\pCan't Make AppleEvent",err);
AEDisposeDesc(&finderTarget);
AEDesc directObjectSpecifier;
AEDesc keyData;
AEDesc nullDescriptor;
AECreateDesc(typeNull, NULL, 0, &directObjectSpecifier);
AECreateDesc(typeNull, NULL, 0, &keyData);
AECreateDesc(typeNull, NULL, 0, &nullDescriptor);
err=AECreateDesc(typeType, (Ptr)&theType, sizeof(DescType),&keyData);
if (err) showError("\pCannot make pSelection type",err);
err=CreateObjSpecifier(cProperty,&nullDescriptor,formPropertyID,&keyData,true,&directObjectSpecifier);
/* {
Handle x;
AEPrintDescToHandle(&directObjectSpecifier,&x);
printf("\n\nDirectObjectSpecifier: %s",*x);
DisposeHandle(x);
} */
if (err) showError("\pCould not create Object",err);
err=AEPutParamDesc(&ae,keyDirectObject, &directObjectSpecifier);
if (err) showError("\pCannot put keyDirectObject",err);
AEDisposeDesc(&directObjectSpecifier);
AEDesc dataDescriptor,newDesc;
AECreateDesc(typeNull, NULL, 0, &dataDescriptor);
AECreateDesc(typeNull, NULL, 0, &newDesc);
err=AECreateDesc(typeType,(Ptr)&theOtherType,sizeof(DescType),&dataDescriptor);
if (err) showError("\pCould not create typeAlias",err);
err=AECoerceDesc (&dataDescriptor,typeAEList,&newDesc);
AEDisposeDesc(&dataDescriptor);
if (err) showError("\pCan't Coerce!",err);
err=AEPutParamDesc(&ae,keyAERequestedType, &newDesc);
if (err) showError("\pCannot put RequestedType!",err);
AEDisposeDesc(&newDesc);
AESendMode mode = kAEWaitReply;
err = AESend(&ae, reply, mode, kAENormalPriority,
kAEDefaultTimeout, nil, nil);
{
{
Handle xx;
AEPrintDescToHandle(&ae,&xx);
CFStringRef
string=CFStringCreateWithFormat(NULL,NULL,CFSTR("Sent: %s\n\n"),*xx);
CFShow(string);
if (string) CFRelease(string);
DisposeHandle(xx);
}
}
if (err) showError("\pCan't Send!",err);
{
{
Handle xx;
AEPrintDescToHandle(reply,&xx);
CFStringRef
string=CFStringCreateWithFormat(NULL,NULL,CFSTR("Reply: %s\n\n"),*xx);
CFShow(string);
if (string) CFRelease(string);
DisposeHandle(xx);
}
}
AEDisposeDesc(&ae);
return err;
//return noErr;
}
AEDesc GetAddressOfFinder()
{
OSErr err=noErr;
ProcessSerialNumber psn;
ProcessInfoRec theProc;
AEAddressDesc finderAddressDescriptor;
// Initialize the process serial number to specify no process.
psn.highLongOfPSN = 0;
psn.lowLongOfPSN = kNoProcess;
// Initialize the fields in the ProcessInfoRec, or we'll have memory
// hits in random locations.
theProc.processInfoLength = sizeof(ProcessInfoRec);
theProc.processName = nil;
theProc.processAppSpec = nil;
theProc.processLocation = nil;
// Loop through all processes, looking for the Finder.
while (true)
{
err=GetNextProcess(&psn);
if (err) showError("\pCannot get next process",err);
err=GetProcessInformation(&psn, &theProc);
if (err) showError("\pCannot get process info",err);
if ((theProc.processType == 'FNDR') &&
(theProc.processSignature == 'MACS'))
break;
}
err = AECreateDesc(typeProcessSerialNumber, (Ptr) &psn,
sizeof(ProcessSerialNumber), &finderAddressDescriptor);
return finderAddressDescriptor;
}
#endif
Ack, at 9/24/01, Tae-Won Ha said:
I've got a question:
How can I get the finder selection??? I want to do file operations
with files selected in the front most finder window.
--
Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug
Unsanity: Unsane Tools for Insane People