<!-- The old Standard Suite: run, reopen, open, print, and quit. -->
<command name="open" code="aevtodoc" description="Open an object.">
<direct-parameter description="The file(s) to be opened." type="file"/>
</command>
Now, I use Script Editor to send this script:
tell application "MyApp"
open file "Tiger:Users:dhoerl:Development:images:Pict.tif"
end tell
MyApp is already running - I launch it from XCode using Run (to get
the NSLogs).
It fails with this message:
26:79: execution error: MyApp got an error: NSInternalScriptError (8)
So, I look at the log pane in XCode, and there are two complaints
that NSCFString does not respond to "count".
* * *
So, I dig deep trying to figure out how to track this down. After a
few dead ends, I finally decide to create a category on NSApplication
with a method called "XhandleOpenScriptCommand:" that then forwards
messages as [self handleOpenScriptCommand:xxx], as well as change the
sdef replacing "handleOpenScriptCommand" with
"XhandleOpenScriptCommand".
I add some more NSLogs and see this happen. In fact, I print out the parameter:
2006-09-07 18:17:28.914 ImageViewer[19585] GOT IT ! Standard Suite.open
Direct Parameter: file://localhost/Users/dhoerl/Development/images/Pict.tif
Receivers: (null)
Arguments: {"" =
file://localhost/Users/dhoerl/Development/images/Pict.tif; }
NSScriptCommand
I still get the errors. So, I create a category on NSString with
methods of "count" (and to cut this short a bit) objectAtIndex:.
Now, I can see that the URL above, when turned into a NSString, is
having messages sent to it as if its an NSArray!
So, feeling like I am making progress, I just have the NSString's
count method return 1, and the "objectAtIndex:index" just return self.
Voila! Now the image opens every time.
As you might imagine, I'm not going to ship this code to anyone anytime soon!!!