【发布时间】:2011-12-28 20:39:39
【问题描述】:
如何在 Cocoa-Applescript 中创建 NSOpenPanel?有什么好的教程吗?我熟悉 Applescript,但不是真正的 Cocoa 部分。 NSOpenPanel 需要nib 吗?我正在做一个 Automator 动作。 See my previous question.
【问题讨论】:
标签: cocoa applescript automator nsopenpanel
如何在 Cocoa-Applescript 中创建 NSOpenPanel?有什么好的教程吗?我熟悉 Applescript,但不是真正的 Cocoa 部分。 NSOpenPanel 需要nib 吗?我正在做一个 Automator 动作。 See my previous question.
【问题讨论】:
标签: cocoa applescript automator nsopenpanel
Shane Stanley 的 PDF 书 AppleScriptObjC Explored 是 AppleScriptObjC 教程中的一本 - 几乎所有来自 Apple 的示例都在现有的 ObjC 文档中,需要进行转换。
您可以在操作界面中使用 Automator 路径弹出按钮,但基本的打开面板如下所示(它不需要自己的 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 先生提供)可以从编辑器中使用。
【讨论】: