【问题标题】:How do I populate a popup button with AppleScript?如何使用 AppleScript 填充弹出按钮?
【发布时间】:2012-09-04 16:41:42
【问题描述】:

我在“网络”周围的各个地方都发现了这个 sn-p 代码:

tell window 1
  tell menu of popup button 1
    delete every menu item
    repeat with catListItem in catList
      make new menu item at end of menu items with properties {title:catListItem}
    end repeat
  end tell
end tell

当我在 Cocoa-AppleScript 应用程序的 AppDelegate 脚本中使用它时,Xcode 给我一个错误:*t2t_AppDelegate.applescript:25: error: Expected end of line but found identifier。 (-2741)*(第 25 行是“告诉菜单...”)

我不确定我错过了什么,这将使我能够使用从另一个应用程序中提取的术语列表 (catList) 动态填充弹出按钮。有什么建议吗?

【问题讨论】:

    标签: applescript


    【解决方案1】:

    除非您运行的东西早于 Snow Leopard,否则您似乎使用的是 AppleScript Studio 术语(在 Snow Leopard 中已弃用)。使用当前的 AppleScriptObjC 框架,用户界面项通过插座属性引用,例如:

    property myPopUp : missing value
    

    在界面编辑器中,此属性连接到您的弹出按钮,它允许您将它与 NSPopupButton 类及其父类中的各种方法一起使用,例如 addItemsWithTitles。定义并连接所有内容后,您将使用以下内容:

    set catList to {"next item", "another item", "Items added"}
    myPopUp's addItemsWithTitles_(catList)
    

    【讨论】:

    • 谢谢,瑞德!我现在有一些事情要做,以“正确”的方式执行 AppleScript。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-25
    • 1970-01-01
    • 2016-08-01
    • 1970-01-01
    • 2013-07-12
    • 2016-08-14
    • 1970-01-01
    相关资源
    最近更新 更多