gpt4 book ai didi

objective-c - NSUserScriptTask : accepted file types?

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:25 25 4
gpt4 key购买 nike

我正在使用 NSUserScriptTask 来运行用户放置在应用程序脚本目录中的脚本。但是,我发现很难找出 NSUserScriptTask 接受的已知脚本类型和 docs也没有太大帮助...有什么想法吗?

到目前为止,我已经尝试了这些:

  • .sh
  • .applescript
  • .scpt
  • .scptd
  • .txt

并且无法让它们中的任何一个工作(initWithURL:error: 方法返回 nil)

编辑:我忘了包括错误!傻我...这是日志上打印的内容:

Error Domain=NSCocoaErrorDomain Code=259 "The file “Untitled.applescript” couldn’t be opened because it isn’t in the correct format." UserInfo=0x100121f50 {NSURL=file://localhost/Users/path to file/Untitled.applescript, NSFilePath=/Users/path to file/Untitled.applescript}

最佳答案

The documentation for NSUserScriptTask声称直接实例化该类将适用于任何有效文件并返回适当类型的任务:

The returned object will be of one of the specific sub-classes (NSUserUnixTask, NSUserAppleScriptTask, and NSUserAutomatorTask), or nil if the file does not appear to match any of the known types.

If invoked from a subclass, the result will be that class or nil.

实际上,我发现(自 10.8.2 起)NSUserScriptTask 无条件返回 nil 和“这是什么我什至不知道”错误。看来你需要自己实例化正确的任务子类。大概值filing a bug .

要测试文件是否可用作脚本任务(例如,在 Open 面板验证方法中),我只能建议尝试实例化这三个类中的每一个,如果有则返回 YES其中一个成功,如果全部失败则NO

关于objective-c - NSUserScriptTask : accepted file types?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15603062/

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