Problem: 1657921

Title: (AppleScript) MacApp doesn't AEOpen Event

Received: May 22 1997 4:37PM


I need help quickly: I'm working on adding support to my/our MacApp application so the new LaserWriter 8.5.1 driver can redirect PS output to it, so I need to be able to correctly handle the 'odoc' event. In so doing, I've noticed that the app, or, for that matter, any of the example MacApp applications (Demo Text is my testbed now) cannot handle the 'odoc' event properly.

Here's my simple test scenario:

1. Build DemoText68K_d
2. launch DemoText, create a file, save it as "try me"
3. create a simple script using the Script Editor:
tell application "DemoText68K_d"
	open "try me"
end tell
4. make certain the script and the "try me" are in the same folder as the 
DemoText app
5. run the script and watch the DemoText app not handle it; instead it 
reports the -1700 error.
Question: how do I get this to work? I build the MacApp libs and headers with qAttach and all the other stuff.

By placing a breakpoint at UFailure::Failure(), we find the following when attempting to send an 'odoc' event to DemoText to open a file that was created by DemoText (remember, this call-chain is in reverse order):

TOSADispatcher::DispatchHandlerGlue()
TOSADispatcher::DispatchHandler()
MScriptableObject::HandleScriptCommand()
TApplication::DoScriptCommand()
TODocCommand::IODocCommand()
TFilesCommand::IFilesCommand()
TFilesCommand::GetFilesList()
TAppleEvent::ReadHandleList()
FailOSErr(-1700)
Failure()
All the appropriate SIZE flags are set on the app, as the example is right out of the box.
The bug only shows up if the AppleScript says
  open file "try me"
A workaround is to use the alias form of the Open command in the script:
  open alias "try me"

When MacApp gets AEOpen event, it creates a CFile object and resolves the target object to it. Unfortunately, CFile class doesn't have AppleEvent support. A quick fix is overriding DoAEOpen method in CFile and handling it in the same way as TApplication class does.
Added method TFile::DoAEOpen, which tells the application to post a TODocCommand.
It doesn't work for the default file in desktop because default file name can't be coerced to file alias when retrieving the file alias from the event record. I am not sure it is MacApp's problem or AppleScript's problem since you can't do the same in apple script. The developer who reported the bug provided a solution which is installing a coerce handler. Maybe we should use it.