【问题标题】:Keyboard shortcuts in an AppleScript list dialogAppleScript 列表对话框中的键盘快捷键
【发布时间】:2015-02-03 18:07:47
【问题描述】:

我正在寻找一种方法来为 AppleScript 中列表对话框中的项目分配键盘快捷键。

我正在使用以下内容来显示一长串文件夹名称,并且正在寻找一种从列表中选择项目的简单方法。

set selectedFolderName to {choose from list folderList}

目前列表显示如下:

Office
Personal
Projects
... 
Vendors

我必须使用光标键或鼠标向下导航列表才能选择一个项目。我希望能够显示:

a) Office
b) Personal
c) Projects
... 
m) Vendors

或:

Office
Personal
pRojects
... 
Vendors

然后我可以按 C 键(第一个示例)或 R 键(第二个示例)来选择“项目”。

我研究了 AppleScript 文档,例如它,并进行了广泛的搜索,但未能找到实现此目的的方法。

【问题讨论】:

    标签: dialog applescript keyboard-shortcuts


    【解决方案1】:

    我不完全确定这是否是您想要的,但我使用下面的结构,这样我可以按“a”选择第一项,“b”选择第二项,依此类推.

    set litems to {"apples", "pears", "banana", "oranges", "plums", "grapes"}
    
    set deli to "." & space & space
    repeat with i from 1 to (count litems)
        set item i of litems to character id (i + 96) & deli & item i of litems
    end repeat
    log litems
    set theRes to choose from list litems
    (*a.  apples, b.  pears, c.  banana, d.  oranges, e.  plums, f.  grapes*)
    set origItem to text 5 thru -1 of item 1 of theRes
    log origItem
    —> plums    
    

    【讨论】:

      【解决方案2】:

      您所要求的第二个版本是不可能的。但是,第一个是。这种功能没有内置任何内容,但您可以为它构建自己的子例程。您可以在列表项前添加字母或数字(我将使用数字,因为它更简单)。

      on choose_from_list_with_shortcut(ls)
          -- prepend the choices with "1) "
          repeat with i from 1 to (count ls)
              set item i of ls to (i as string) & ") " & item i of ls
          end repeat
      
          set chosenItems to choose from list ls
      
          -- strip the prefixes from the chosen items
          repeat with i from 1 to (count chosenItems)
              set item i of chosenItems to text 4 thru -1 of item i of chosenItems
          end repeat
      
          return chosenItems
      end choose_from_list_with_shortcut
      

      另一种选择是直接开始输入。就像在 Finder 中一样,如果您键入字母“pro”,列表将突出显示“项目”。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多