【发布时间】:2014-09-22 23:24:26
【问题描述】:
尝试通过 Objective-C 中的 Scripting Bridge 自动查看 Apple Remote Desktop 中的计算机:
@try {
SBApplication *RD = [SBApplication applicationWithBundleIdentifier:@"com.apple.RemoteDesktop"];
// (code to check for ARD running and installed omitted here)
[RD activate]; // works just fine
RemoteDesktopComputer *computer = [[[RD classForScriptingClass:@"computer"] alloc] initWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
ipAddress,@"InternetAddress", // looked up from header
nil
]
];
// attempt to add it to a container first:
[(SBElementArray*)[(RemoteDesktopApplication*)RD computers] addObject:computer];
// this is what raises the exception:
[computer observeZooming:Nil];
}
@catch (NSException *e) {
NSLog(@"Exception: %@", [e description]);
}
运行它会在日志中产生以下异常:
Exception: *** -[SBProxyByClass observeZooming:]: object has not been added to a container yet; selector not recognized [self = 0x6050004819b3]
我已经对这个主题进行了尽可能多的研究,并且了解到 SB 并不是最容易处理的,因为它是如何连接到引擎盖下的,但是任何本地 Scripting Bridge 的专家或资深人士(不请使用 obj-c 以外的第三方框架或语言)非常感谢。
执行所有先决条件,例如链接到 ScriptingBridge.framework 和导入 Remote Desktop.h - 类型转换是为了避免在构建时似乎不可避免的链接时错误...
编辑 1: 阅读有关 SBObject(RemoteDesktopComputer 的父级)的文档说它是一个引用而不是实际实例,您可以通过调用 SBObject 的 get 方法(返回 id)来获取它。所以我也尝试运行它,但不幸的是得到了相同的结果:
[[computer get] observeZooming:Nil];
这是关于 SBObject 的文档:https://developer.apple.com/library/mac/documentation/cocoa/Reference/SBObject_Class/SBObject/SBObject.html#//apple_ref/occ/instm/SBObject/get
还在尝试中……
【问题讨论】:
-
你能检查哪个函数抛出异常,例如通过使用异常断点?
-
Stepping into observeZooming: 只是简单地抛出异常,就像它不使用断点一样,确认 observeZooming: 确实是触发异常的方法,但没有提供任何关于原因的见解。查看我的编辑 - 尝试使用和不使用“get”选择器来取消引用对象并每次都得到相同的结果
-
我没用过Scripting Bridge,所以可能想不出办法,但是
[RD computers]的返回值是非nil吗? -
我用 NSLog 输出运行了一些测试代码来检查它确实不是 Nil...但是,这可能是因为正在进行一些取消引用抽象 - 请查看以下详细说明:stackoverflow.com/questions/1309958/…
标签: objective-c cocoa applescript scripting-bridge