macos - 是否可以授予沙盒应用程序访问从 AppleScript 发送的文件的权限?

标签 macos scripting applescript appstore-sandbox

我正在向我的沙盒 Mac App Store 应用程序添加 AppleScript 支持。我希望用户能够使用我编写的命令通过脚本将文件添加到应用程序,如下所示:

add file at path "/path/to/some/file/on.disk"

我将命令的参数指定为 file 类型,因此它以 NSURL 的形式传入我的应用程序,并且我可以看到文件 URL 的路径 ( >po url.path) 在调试器中。

这是 sdef 文件中命令的定义:

<!-- Contained by a suite -->
<command name="add file at path" code="ABCDABCD">
    <direct-parameter description="A file to add to the app" type="file" />
</command>

当我尝试为此文件创建安全范围的书签时,出现错误:

Could not open() the item

我需要能够在应用程序的后续启动时读取该文件,这就是我创建书签的原因。此书签创建代码:

NSData *fileBookmark = [url bookmarkDataWithOptions:NSURLBookmarkCreationWithSecurityScope
                     includingResourceValuesForKeys:nil
                                      relativeToURL:nil
                                              error:&error];

我尝试用 [url start(stop)AccessingSecurityScopedResource] 包围代码,但这没有什么区别。

更新

我还确定应用程序无法读取文件的内容,或将其复制到应用程序的容器中。除了文件路径之外,脚本化应用无法访问该文件。

更新2

我还尝试将脚本放在 ~/Application Scripts/bundleid (NSApplicationScriptsDirectory) 目录中,并从内部的 NSUserScriptTask 运行它我的 Cocoa 代码,产生了相同的结果(URL 处的文件仍然不可读)。

最佳答案

好吧,事实证明这个问题与我的应用程序无关,而是与我用来调用它的 AppleScript 有关。您需要发送文件句柄或别名,如下所示:

add file at path posix file "/path/to/some/file/on.disk"
add file at path "path:to:some:file:on.disk" as alias

当你只是给出一个路径(POSIX 或其他)时,它仍然以 NSURL 的形式出现,因此我很困惑,但没有在沙箱中打洞。

这个行为并不明显,而且很难排查,所以我filed a Radar .

关于macos - 是否可以授予沙盒应用程序访问从 AppleScript 发送的文件的权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28155444/

相关文章:

c++ - Mac OS 上 CodeBlocks 中的调试器设置

windows - VBScript当前目录+子目录?

linux - 在行字符串中找到最大数并显示两列 - linux

xml - Applescript - 解析 XML

git - 如何从 Mac OS X 10.5.8 卸载 git 版本 1.6.5.1

macos - docker 登录失败 -> x509 : certificate signed by unknown authority . 。 "crypto/rsa: verification error"

regex - 我如何用 sed 表达这个正则表达式?

linux - 如何让用户以 root 权限运行脚本?

macos - 在 2x-click 上运行 applescript

path - Applescript中的错误-10004和错误-10000是什么