NSUserScriptTask:接受的文件类型? [英] NSUserScriptTask: accepted file types?

查看:849
本文介绍了NSUserScriptTask:接受的文件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用NSUserScriptTask来运行用户放置在应用程序脚本目录中的脚本。然而,我发现很难找出哪些是已知类型的脚本NSUserScriptTask接受和 docs 对帮助不大...任何想法?

I'm using NSUserScriptTask to run scripts the user placed in the Application Scripts directory. However, I'm finding it hard to find out which are the known types of scripts that NSUserScriptTask accepts and the docs don't help much either... Any ideas?

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

So far I've tried these:


  • .sh

  • .applescript

  • .scpt

  • .scptd

  • .txt

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

并且没有任何工作( initWithURL:error:方法返回nil)

And coudn't get any of them to work (the initWithURL:error: method returns nil)

编辑:
我忘了包含错误!愚蠢的我...这是什么打印在日志上:

I forgot to include the error! Silly me... Here's what gets printed on the log:

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}


推荐答案

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

The documentation for NSUserScriptTask claims that instantiating that class directly will work on any valid file and return the appropriate kind of task:


返回的对象将是一个特定的子类( NSUserUnixTask NSUserAppleScriptTask a>和 NSUserAutomatorTask )或 nil (如果文件似乎不匹配任何已知类型)。

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.

如果从子类调用,结果将是该类或 nil

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

在现实中,我发现(从10.8.2开始)NSUserScriptTask无条件地返回 nil 和一个这是什么是我不甚至错误。看来你需要自己实例化正确的任务子类。可能值得提交错误

In reality, I found that (as of 10.8.2) NSUserScriptTask unconditionally returns nil and a "what is this i dont even" error. It seems that you need to instantiate the correct task subclass yourself. Probably worth filing a bug.

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

To test whether a file is usable as a script task (e.g., in an Open panel validation method), all I can suggest is to try instantiating each of the three classes, returning YES if any of them succeeds and NO if all of them fail.

这篇关于NSUserScriptTask:接受的文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆