[PYTHONMAC-SIG] Q: How To Tell The Finder To Launch An App With A Doc?
Mark Roseman
roseman@cpsc.ucalgary.ca
Tue, 17 Sep 1996 20:14:47 -0600
In message <v01540b01ae651892f148@[193.78.237.46]>you write:
> In my BBEdit extension in which I can send Python code to the interpreter I
> would like to give a prompt when the slave script is not running, asking
> the user to locate it and then: Launch The Interpreter With The Script.
> I am told I have to send an AppleEvent to the Finder to do this, but I've
> crawled through most of the stuff on my Inside Mac CD and I Can't Bleedin'
> Find It. Does anyone know what event to send? Or what else to do? I think
> Jack would also like to know, so we can also make a convenient call for
> this in Python / aetools.py. No More Connection Invalid Errors. Please?
here is part of a tcl extension i wrote that did this..
mark
/*
* Launch a file, optionally specifying a type and creator (0L to leave as is).
* This works exactly as if you'd double clicked on the file in the Finder, which
* not surprisingly is how its implemented (via the AppleEvents route of course).
*/
int LaunchFile(OSType creator, OSType type, char *filename) {
FSSpec docFile, dirSpec;
OSErr result;
FInfo docInfo;
AEAddressDesc finderAddress;
AppleEvent theEvent, reply;
long aSig = 'MACS';
AliasHandle DirAlias, FileAlias;
AEDesc fileList;
AEDesc aeDirDesc, listElem;
if ((result = FSMakeFSSpec (0, 0, c2pstr(filename), &docFile)) != noErr) {
return -1;
}
if ((result = FSpGetFInfo(&docFile, &docInfo)) != noErr) {
return -2;
}
if (creator!=(OSType) 0L) {
docInfo.fdCreator = creator;
}
if (type!=(OSType) 0L) {
docInfo.fdType = type;
}
if ((creator!=(OSType)0L) || (type!=(OSType)0L)) {
if ((result = FSpSetFInfo(&docFile, &docInfo)) != noErr) {
return -3;
}
}
if ((result = AECreateDesc(typeApplSignature, (Ptr)&aSig, 4, &finderAddress)) != noErr) {
return -4;
}
if ((result = AECreateAppleEvent('FNDR', 'sope', &finderAddress,
kAutoGenerateReturnID, kAnyTransactionID, &theEvent)) != noErr) {
return -5;
}
FSMakeFSSpec(docFile.vRefNum, docFile.parID, nil, &dirSpec);
NewAlias(nil, &dirSpec, &DirAlias);
NewAlias(nil, &docFile, &FileAlias);
result = AECreateList(nil, 0, 0, &fileList);
HLock((Handle)DirAlias);
AECreateDesc(typeAlias, (Ptr)*DirAlias, GetHandleSize((Handle)DirAlias), &aeDirDesc);
HUnlock((Handle)DirAlias);
if ((result = AEPutParamDesc(&theEvent, keyDirectObject, &aeDirDesc)) == noErr) {
AEDisposeDesc(&aeDirDesc);
HLock((Handle)FileAlias);
AECreateDesc(typeAlias, (Ptr)*FileAlias, GetHandleSize((Handle)FileAlias), &listElem);
HLock((Handle)FileAlias);
result = AEPutDesc(&fileList, 0, &listElem);
}
AEDisposeDesc(&listElem);
result = AEPutParamDesc(&theEvent, 'fsel', &fileList);
AEDisposeDesc(&fileList);
if ((result = AESend(&theEvent, &reply, kAENoReply+kAENeverInteract,
kAENormalPriority, kAEDefaultTimeout, 0L, 0L)) != noErr) {
return -6;
}
if ((result = AEDisposeDesc(&theEvent)) != noErr) {
return -7;
}
if ((result = AEDisposeDesc(&reply)) != noErr) {
return -8;
}
return 0;
}
=================
PYTHONMAC-SIG - SIG on Python for the Apple Macintosh
send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
=================