编码
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 代理中的此代码会导致问题:
// Inject!
[app setSendMode:kAENoReply | kAENeverInteract | kAEDontRecord];
id injectReply = [app sendEvent:'SIMe' id:'load' parameters:0];
if (injectReply != nil) {
SIMBLLogNotice(@"unexpected injectReply: %@", injectReply);
}
(app
适用SBApplication
于 Photoshop。)
因为我需要 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 的发送方式有问题。