【发布时间】:2014-06-05 23:46:03
【问题描述】:
我制作了一个应用程序,它只有一个调用方法的按钮。我想实现调用此方法的 AppleScript 可能性。
我阅读了 Apple 文档并在我的项目中创建了一个 *.sdef 文件,但问题如下:
我不明白 NSScriptCommand 的对象制作,我只想调用我项目中现有的方法,我该怎么做?
这是我的 sdef 文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Live Control">
<suite name="Live Control Suite" code="LivC" description="Live Control Scripts">
<class name="session" code="sess" description="OTN Telnet Control">
<cocoa class="NTLAppDelegate"/>
<responds-to name="gotonext">
<cocoa method="GoToNextFromScript:"/>
</responds-to>
</class>
</suite>
</dictionary>
所以我告诉我使用的类是 NTLAppDelegate,调用的方法是“GoToNext:”
这是我的 .h 文件:
#import <Cocoa/Cocoa.h>
@interface NTLAppDelegate : NSObject <NSStreamDelegate> {
NSInputStream * InputStream;
NSOutputStream * OutputStream;
unsigned char IACcommand[12];
}
- (IBAction)GoToNextButton:(id)sender;
- (id) GoToNextFromScript:(NSScriptCommand *)command;
@property (assign)
IBOutlet NSWindow * TheMainWindow;
@end
还有我的 *.m 文件:
#import "NTLAppDelegate.h"
@implementation NTLAppDelegate
// GoToNext
- (id)GoToNextFromScript:(NSScriptCommand *)command {
[ConnectLog setEditable:YES];
[ConnectLog setString:@"APPLE SCRIPT TEST"];
[ConnectLog setEditable:NO];
return nil;
}
- (IBAction)SkipToNextButton:(id)sender {
[ConnectLog setEditable:YES];
[ConnectLog setString:@""];
[ConnectLog setEditable:NO];
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, (__bridge CFStringRef)[HostField stringValue], [PortField intValue], &readStream, &writeStream);
InputStream = (__bridge NSInputStream *)readStream;
OutputStream = (__bridge NSOutputStream *)writeStream;
[InputStream setDelegate:self];
[OutputStream setDelegate:self];
...... rest is the code for the tcp stream control (input and output) not concerned .....
}
@synthesize TheMainWindow = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}
@end
所以,没有任何效果...当我使用 Apple 脚本编辑器阅读 Apple 脚本字典时, 我可以读取 sdef 文件,但是当我制作类似的 AppleScript 时
告诉应用程序“实时控制 会话 gotonext 结束告诉
我收到一个错误,提示“gotonext”变量未定义。
如果有人能解释我如何写这个小东西,那就太好了。 请注意,老实说,我的 Obj-C / C++ 知识很差, 但我的应用程序正在运行(只是一个带有一个按钮的可可应用程序,它打开一个 tcp 套接字,将 IAC 命令发送到 telnet 会话并编写一个命令)。我只需要 AppleScript 控件就可以了。
【问题讨论】:
标签: objective-c cocoa methods applescript