Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tell app "MyAp to open file "foo" only works with BIZARRE kludge



I have a document based App that is doing a few small things with Applescript. (See my earlier posts on wanting to open a pane in an existing window).

I started my sdef with the NSCoreSuite.sdef as a template.

I have the standard:

<class name="application" code="capp" description="An application&apos;s top level scripting object.">
<cocoa class="NSApplication"/>
...
<responds-to name="open">
<cocoa method="handleOpenScriptCommand:"/>
</responds-to>



and

<!-- 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!!!

What the heck is going on?????


David _______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-implementors mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-implementors/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.