質問

次のAppleScriptコードが正常に動作します:

tell application "Adium" to tell first account to make new chat with contacts {first contact} with new chat window

しかし、どのように私はココアのScriptingBridgeを使用して同じことを行うことができますか?

役に立ちましたか?

解決

一般的に、あなたは、Appleの<のhref =「http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ScriptingBridgeConcepts/Introduction/Introduction.html」のrel =以下のことを行うことができるはずです「nofollowをnoreferrer」>ココアのスクリプティングブリッジプログラミングガイド。開始するには、私はターミナルでsdef /Applications/Adium.app | sdp -fh --basename Adiumを実行することにより、Adiumのためのヘッダファイルを作成した(Adium.hはカレントディレクトリに作成されます)。生成ヘッダファイルは、アップルスクリプトがスクリプト・ブリッジを介して呼び出すことについての手がかりを与えます。

私はに走った問題は、私は(私は新しいチャットをし、多分、新しいウィンドウにそれをフックすることができmake new chat with contacts {...} with new chat windowを行うには、生成されたヘッダファイルに基づいて、道を見ることはできませんが、私は見つけることができなかったということですそれは、コンタクトを取るチャット作るための方法)。

次善の策は、のhref =「http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSAppleScript_Class/Reference/Reference.html」のrel = <使用するかもしれません"nofollowをnoreferrer"> NSAppleScriptはあなたの有効なAppleScriptのコードを実行するためにをます:

NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:@"tell application \"Adium\" to tell first account to make new chat with contacts {first contact} with new chat window"];
NSDictionary *errorDictionary;
NSAppleEventDescriptor *eventDescriptor = [appleScript executeAndReturnError:&errorDictionary];

他のヒント

生のアップルイベントコードを使用しての短い、あなたがすることはできません。しかしにObjC-appscriptするで動作するはずです。 appscriptのASTranslateツールを通して、あなたのAppleScriptコマンドを実行すると、以下のように生成します:

#import "ADGlue/ADGlue.h"
ADApplication *adium = [ADApplication applicationWithName: @"Adium"];
ADReference *ref = [[adium accounts] at: 1];
ADMakeCommand *cmd = [[[[ref make] newChatWindow: ASTrue] withContacts: [NSArray arrayWithObject: [[[[adium accounts] at: 1] contacts] at: 1]]] new_: [ADConstant chat]];
id result = [cmd send];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top