OSAX的AppleEvent处理程序导致其他AppleEvents失败

时间:2011-09-05 14:36:50

标签: objective-c applescript appscript appleevents

代码

from appscript import *
ps = app("Adobe Photoshop CS5")
ps.do_javascript
如果Photoshop尚未运行,则

有效。在这种情况下,它启动Photoshop并找到do_javascript方法。

但是,如果Photoshop已在运行,则该代码将失败并显示异常

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

为什么?

(注意:这是Python appscript代码,但我有同样的错误,有一些更加神秘的消息,使用纯AppleScript。错误是44:54: syntax error: Expected end of line but found identifier. (-2741)。)

SIMBL导致问题。如果我停止SIMBL代理,它就可以工作。

来自SIMBL Agent的此代码导致问题:

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

app是Photoshop的SBApplication。)

由于我需要SIMBL Agent才能工作,因此我不能使用它。所以我需要知道为什么这会造成麻烦。

SIMBL.osax定义代码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>

这是InjectEventHandler中的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/mac/#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;
}

请注意,我也有代码注释掉的问题(已发布)。这意味着SIMBL事件处理程序实际上什么都不做。它仍然会产生问题。

所以要么OSAX包/处理程序中有问题,要么AppleEvent的发送方式有问题。

0 个答案:

没有答案