Cocoa-Applescript NSOpenPanel? [英] Cocoa-Applescript NSOpenPanel?
问题描述
如何在 Cocoa-Applescript 中创建 NSOpenPanel
?有什么好的教程吗?我熟悉 Applescript,但不是真正的 Cocoa 部分.NSOpenPanel 需要 nib
吗?我正在做一个 Automator 动作.查看我之前的问题.
How do I do an NSOpenPanel
in Cocoa-Applescript? Are there any good tutorials? I am familiar with Applescript, but not really the Cocoa part. Do I need a nib
for the NSOpenPanel? I am making an Automator action. See my previous question.
推荐答案
Shane Stanley 的 PDF 书 AppleScriptObjC 探索 是 AppleScriptObjC 教程中的一个 - 来自 Apple 的几乎所有示例都在现有的 ObjC 文档中,需要进行转换.
Shane Stanley's PDF book AppleScriptObjC Explored is the one to get for AppleScriptObjC tutorials - pretty much all of the examples from Apple are in the existing ObjC documentation and would need to be converted.
您可以在操作界面中使用 Automator 路径弹出按钮,但基本的打开面板如下所示(它不需要自己的笔尖):
There is an Automator path pop-up button you can use in your action's interface, but a basic open panel goes something like the following (it doesn't need its own nib):
set defaultDirectory to POSIX path of (path to desktop) -- a place to start
tell current application's NSOpenPanel's openPanel()
setFloatingPanel_(true)
setTitle_("Panel Test")
setPrompt_("Choose") -- the button name
setMessage_("Choose some stuff:")
setDirectoryURL_(current application's NSURL's URLWithString_(defaultDirectory))
setCanChooseFiles_(true)
setCanChooseDirectories_(true)
setShowsHiddenFiles_(false)
setTreatsFilePackagesAsDirectories_(false)
setAllowsMultipleSelection_(true)
set theResult to it's runModal() as integer -- show the panel
if theResult is current application's NSFileHandlingPanelCancelButton then quit -- cancel button
set theFiles to URLs() as list --> a list of NSURLs
end tell
请注意,如果使用 AppleScript 编辑器,则不能直接从编辑器运行 AppleScriptObjC 代码,您需要在 Cocoa-AppleScript 小程序中运行它.有一个 ASObjC Runner 后台应用程序(也是 Stanley 先生提供的)可以不过是在编辑器中使用的.
Note that if using the AppleScript Editor, you can't run AppleScriptObjC code directly from the editor, you need to run it in a Cocoa-AppleScript applet. There is an ASObjC Runner background application (also by Mr. Stanley) that can be used from the editor, though.
这篇关于Cocoa-Applescript NSOpenPanel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!