可可-Applescript NSOpenPanel?

发布于 2024-12-15 10:57:24 字数 242 浏览 1 评论 0原文

如何在 Cocoa-Applescript 中创建 NSOpenPanel ?有什么好的教程吗?我熟悉 Applescript,但不太熟悉 Cocoa 部分。 NSOpenPanel 需要nib 吗?我正在做一个自动操作。 查看我之前的问题

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲸落 2024-12-22 10:57:24

Shane Stanley 的 PDF 书 AppleScriptObjC Explored 是 AppleScriptObjC 教程的一本 - 几乎所有Apple 的示例位于现有 ObjC 文档中,需要进行转换。

您可以在操作界面中使用一个 Automator 路径弹出按钮,但基本的打开面板如下所示(它不需要自己的笔尖):

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 先生开发),可以不过,是从编辑器中使用的。

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.

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文