gpt4 book ai didi

objective-c - 为什么 OSA_LIBRARY_PATH 不能像为 JXA 记录的那样工作?

转载 作者:搜寻专家 更新时间:2023-10-30 19:56:02 24 4
gpt4 key购买 nike

根据 Apple's Developer Docs Library 全局允许导入已编译的脚本,以便它们可以用作当前脚本中的库。如果您要使用位于 ~/Library/Script LibrariesmyLibName.scpt 执行类似以下代码的操作,这会很好地工作:

myLib = Library('myLibName');
myLib.myLibMethod() // Works just fine

但是,文档还声称可以导出一个环境变量 — OSA_LIBRARY_PATH 包含一串 : 分隔路径 — 和 Library() 将在 继续其默认路径之前遵循该路径列表:~/Library/Script Libraries。你知道,就像 bash 环境变量 Path。这是下面的相关文档;它描述了路径层次结构:

The basic requirement for a script to be a script library is its location: it must be a script document in a “Script Libraries” folder in one of the following folders. When searching for a library, the locations are searched in the order listed, and the first matching script is used:

  1. If the script that references the library is a bundle, the script’s bundle Resources directory. This means that scripts may be packaged and distributed with the libraries they use.
  2. If the application running the script is a bundle, the application’s bundle Resources directory. This means that script applications (“applets” and “droplets”) may be packaged and distributed with the libraries they use. It also enables applications that run scripts to provide libraries for use by those scripts.
  3. Any folders specified in the environment variable OSA_LIBRARY_PATH. This allows using a library without installing it in one of the usual locations. The value of this variable is a colon-separated list of paths, such as /opt/local/Script Libraries:/usr/local/Script Libraries. Unlike the other library locations, paths specified in OSA_LIBRARY_PATH are used exactly as-is, without appending “Script Libraries”. Supported in OS X v10.11 and later.
  4. The Library folder in the user’s home directory, ~/Library. This is the location to install libraries for use by a single user, and is the recommended location during library development.
  5. The computer Library folder, /Library. Libraries located here are available to all users of the computer.
  6. The network Library folder, /Network/Library. Libraries located here are available to multiple computers on a network.
  7. The system Library folder, /System/Library. These are libraries provided by OS X.
  8. Any installed application bundle, in the application’s bundle Library directory. This allows distributing libraries that are associated with an application, or creating applications that exist solely to distribute libraries. Supported in OS X v10.11 and later.

问题是它不起作用。我试过导出 OSA_LIBRARY_PATH 变量——通过我的 .zshrc 文件全局导出——然后通过脚本编辑器和 运行一个示例脚本,就像上面的脚本一样>osascript 可执行文件。什么都不管用;我收到“找不到文件”错误。我找到了这个 thread-where-the-participants-give-up-hope在线的;它并没有解释太多。有什么想法吗?

在某种程度上相关的注释中,Scripting Additions 套件提供了另外两种方法——loadScriptstoreScript——它们看起来可能很有用这里。不幸的是,当您尝试使用它们时,osascript 会给您带来麻烦。不过,我确实设法从使用 loadScript 的已编译脚本中返回了看起来像十六进制缓冲区的内容。不管怎样,如果你们能就此发表任何见解,我们将不胜感激。谢谢。

最佳答案

在启用系统完整性保护的情况下运行时,受限的可执行文件将忽略 OSA_LIBRARY_PATH 环境变量。

要解决此限制,您可以 turn off SIP ,或者您可以使用不受限制的可执行文件。

例如,要使 osascript 不受限制,您应该先制作一份副本,然后使用临时签名重新签名:

cp /usr/bin/osascript ./osascript
codesign -f -s - ./osascript

一旦您拥有不受限制的 osascript,您就可以像这样设置 OSA_LIBRARY_PATH 环境变量来运行它:

OSA_LIBRARY_PATH="/path/to/libs" ./osascript path/to/script.scpt

关于objective-c - 为什么 OSA_LIBRARY_PATH 不能像为 JXA 记录的那样工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35389058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com