如何在Cocoa-Applescript中执行NSOpenPanel?有什么好的教程吗?我熟悉Applescript,但不是真正的Cocoa部分。NSOpenPanel需要nib吗?我正在执行Automator操作。See my previous question。
发布于 2011-11-15 09:49:19
Shane Stanley的PDF书籍AppleScriptObjC Explored是AppleScriptObjC教程中的一个-几乎所有来自苹果的示例都在现有的ObjC文档中,需要进行转换。
您可以在操作界面中使用Automator path弹出按钮,但基本的打开面板如下所示(它不需要自己的笔尖):
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 applet中运行它。不过,有一个ASObjC Runner后台应用程序(也是斯坦利先生开发的),可以在编辑器中使用。
https://stackoverflow.com/questions/8125563
复制相似问题