从另一个沙盒应用程序使用ScriptingBridge我试图从另一个沙盒应用程序脚本(我写了)沙盒应用程序。我在目标应用程序的sdef中设置了访问组,并在脚本应用程序的沙箱权利中配置了权利。但是,当我尝试将Apple事件发送到目标(使用ScriptingBridge)时,我看到在控制台中登录了warning: failed to get scripting definition from ~/<snip>/MyApp.app; it may not be scriptable.
(目标应用程序的路径是正确的)。AppleScripting沙盒应用程序使用ScriptingBridge
我已经能够使用Sketch示例代码应用程序的轻微修改版本以及使用脚本桥的非常简单的测试应用程序来重现该问题。我在Sketch.sdef中为许多元素添加了<access-group identifier="com.apple.CocoaExamples.Sketch.Draw" access="rw"/>
,并为Sketch打开了沙盒。
然后,在我的测试程序,我打开具有以下权利沙箱:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.CocoaExamples.Sketch</key>
<array>
<string>com.apple.CocoaExamples.Sketch.Draw</string>
</array>
</dict>
</dict>
</plist>
该应用程序将执行以下操作:
#import "ViewController.h"
#import "Sketch.h"
@implementation ViewController
- (IBAction)draw:(id)sender {
SketchApplication *sketch = [SBApplication applicationWithBundleIdentifier:@"com.apple.CocoaExamples.Sketch"];
if (![sketch isKindOfClass:[NSClassFromString(@"SketchApplication") class]]) {
NSLog(@"Unable to get SketchApplication for Sketch");
}
}
@end
在调用-applicationWithBundleIdentifier:
,在“警告:未能获取脚本定义“消息,并且返回的对象是SBApplication
的实例,而不是SketchApplication
。
如果我在测试应用程序中关闭沙盒,则不会记录该错误,并且-applicationWithBundleIdentifier:
会按预期返回SketchApplication
。如果我添加com.apple.security.temporary-exception.apple-events
权利也是如此,但我相信这不太可能通过应用商店审查。
我错过了定义目标sdef中的访问组并添加com.apple.security.scripting-targets
权利的内容吗?这对任何人都适用吗?
我上传的测试程序和修改我的素描这里的项目:https://www.dropbox.com/s/cdml9n5npu8o2m3/SandboxScriptTest.zip?dl=0
看来只有当目标应用程序已经*运行时才会发生这种情况;否则它会起作用。 –
这很有趣。在我的测试应用程序中,如果Sketch未运行,单击Draw按钮将打开Sketch,并调用“-applicationWithBundleIdentifier:'成功。但是,在下一次单击,现在Sketch正在运行时,它将失败。 –
是的,奇怪的是,它实际上第一次运作,实际上不需要临时例外授权。 –