コード
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);
}
(Photoshop用です。app
)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の送信方法に問題があります。