开发者

AppleEvent handler from OSAX causes other AppleEvents to fail

开发者 https://www.devze.com 2023-04-02 07:23 出处:网络
The code from appscript import * ps = app(\"Adobe Photoshop CS5\") ps.do_javascript works if Photoshop is not running yet. In that case, it starts up Photoshop and it finds the do_javascript method

The code

from appscript import *
ps = app("Adobe Photoshop CS5")
ps.do_javascript

works if Photoshop is not running yet. In that case, it starts up Photoshop and it finds the do_javascript method.

However, if Photoshop is already running, that code fails with the exception

AttributeError: Unknown property, element or command: 'do_javascript'

Why?

(Note: This is Python appscript code but I have the same error, with a somewhat more cryptic message, with pure AppleScript. The error is 44:54: syntax error: Expected end of line but found identifier. (-2741).)

SIMBL causes the problem. If I stop the SIMBL Agent, it works.

This code from the SIMBL Agent causes the problem:

// Inject!
[app setSendMode:kAENoReply | kAENeverInteract | kAEDontRecord];
id injectReply = [app sendEvent:'SIMe' id:'load' parameters:0];
if (injectReply != nil) {
    SIMBLLogNotice(@"unexpected injectReply: %@", injectReply);
}

(app is a SBApplication for Photoshop.)

As I need SIMBL Agent to work, it is not really a solution for me to not use this. So I need to know why this is creating trouble.

SIMBL.osax defines the handler for the code SIMeload:

<dict>
    <key>Events</key>
    <dict>
        <key>SIMeload</key>
        <dict>
            <key>Handler</key>
            <string>InjectEventHandler</string>
            <key>ThreadSafe</key>
            <false/>
            <key>Context</key>
            <string>Process</string>
        </dict>
    </dict>
</dict>

This is InjectEventHandler in SIMBL.osax:

// This is the handler function which is called when the send the AppleEvent 'SIMeload'.
// This is send from the SIMBL Agent in SIMBLAgent.m:injectSIMBL.
// See http://developer.apple.com/library/ma开发者_如何转开发c/#technotes/tn1164/_index.html "Scripting Additions for Mac OS X".
// See http://developer.apple.com/legacy/mac/library/documentation/AppleScript/Conceptual/AppleEvents/AppleEvents.pdf "Apple Event Programming Guide".
OSErr pascal InjectEventHandler(const AppleEvent *ev, AppleEvent *reply, SInt32 refcon)
{
    OSErr resultCode = noErr;
    //SIMBLLogInfo(@"load SIMBL plugins");
    //[SIMBL installPlugins];
    return resultCode;
}

Note that I also have the problem with the code commented out (as posted). This means that the SIMBL event handler is actually doing nothing. And it still creates the problem.

So either there is something wrong in the OSAX bundle/handler or there is something wrong in how the AppleEvent is sent.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号