7

我们正在MacOSX 10.9上使用Qt 5.2.0.Framework为Mac App Store开发应用程序。如何从Mac上的沙盒应用程序运行AppleScript(OS X)

这是一个简单的AppleScript,它创建一个Microsoft Excel工作簿并保存到任何位置。

tell application "Microsoft Excel" 
    set myworkbook to make new workbook 
    set fname to POSIX file "/Private/var/root/Download/ExcelFile" as text 
    save workbook as myworkbook filename fname 
end tell 

上述脚本保存为/Library/ApplicationScript/Untitled.scpt

在应用程序中,我们使用Cocoa框架来执行AppleScript。

此AppleScript在非沙盒应用程序中工作。它在沙盒应用程序中失败。

我的问题是:你如何在沙盒应用程序中使用AppleScript?或者是否有替代方案?

请告诉我解决方案,因为我的项目正在被这个延迟。

感谢

enter image description here

enter image description here

+0

我已经重新格式化了您的问题以使其更具可读性;请看看源代码,以便您将来可以自己执行此格式化;你首先说脚本文件名是'new.scpt',但是你的Objective-C代码引用'Untitled.scpt'。我对沙盒知之甚少,但我不希望诸如'/ private'和'/ Library'之类的路径可以从沙盒应用程序写入。 “.scpt”文件如何保存到目标位置? – mklement0

+0

这个,苹果脚本保存为Untitled.scpt(不是new.scpt)在这个路径中“/Library/ApplicationScript/Untitled.scpt”。当使用cocoa执行脚本时,创建的excel文件保存为/ Private/var/root/Download/ExcelFile这个位置 – anuj

+0

在我的排队中将关键字“new.scpt”替换为“Untitled.scpt” – anuj

回答

8

有两个问题与您的代码:

  • Excel中可能还没有通过增加一个阵列支持com.apple.security.scripting-targets,所以你需要com.apple.security.temporary-exception.apple-events(见here如何找出它是否支持它,并在这里how to work with the temporary exception

  • 脚本目标以及com.apple.security.temporary-exception.apple-events的权利是捆绑标识符的数组。你会看到它在Xcode这样的:在共享位置就像/Library/ApplicationScriptcom.apple.security.temporary-exception.apple-events

  • 在Mac App Store中的应用程序不能安装任何东西(见App Store Review Guidelines第2.15节)。您需要将脚本存储在Container中并从此处运行它。

+0

我不明白com.apple.security.temporary-exception.apple-events的关键值或授权文件中的com.apple.security.scripting-targets。这个键的正确值是什么?它在沙盒应用程序上执行苹果脚本。 – anuj

+0

感谢泰姬陵解决我的项目的大问题。 – anuj

+0

无法执行使用可可的do shell脚本命令。可可代码假人是看到我的问题上面。 NSAppleEventDescriptor的描述符变量将返回一个NULL值。我的脚本文件包含此命令“do shell script”diskutil info/| grep \“Volume Nmae:\”“” – anuj

2

您需要add the com.apple.security.scripting-targets sandboxing entitlement从沙盒中的脚本的其他应用程序。

+0

我是MAC上的新用户,在授权中,我为com.apple.security.scripting-targets创建了一个新条目。但是如何创建application-group-id。 – anuj

+0

您只需将上述链接中的键/值(它有一个示例)添加到.entitlements文件中即可。 – indragie

+0

请参阅权利文件的屏幕截图附加到此问题。在沙盒应用程序中添加脚本目标键,但新创建的沙盒应用程序不执行苹果脚本。 – anuj

相关问题