gpt4 book ai didi

cocoa -Applescript NSOpenPanel?

转载 作者:行者123 更新时间:2023-12-03 17:15:27 33 4
gpt4 key购买 nike

如何在 Cocoa-Applescript 中创建 NSOpenPanel?有什么好的教程吗?我熟悉 Applescript,但不太熟悉 Cocoa 部分。 NSOpenPanel 需要nib 吗?我正在做一个自动操作。 See my previous question .

最佳答案

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 先生开发)。

关于 cocoa -Applescript NSOpenPanel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8125563/

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