查找和替换列表 Applescript 中每个项目的文本

Finding and Replacing Text for every item in a list Applescript

我有一个 Applescript 快捷方式列表,我想用文本替换一些特殊字符。

我当前的列表如下所示:

set hotkeyShortcutList to  {"$", "U", "J", "G", "R", "⇧+R", "⇧+Y", "⇧+G", "⇧+B", "⇧+P", "⇧+⌫", "⌃+M", "⌃+W", "⌃+S", "⌃+X", "⌃+C", "⌃+V", "⌃+N", "⇧+⌃+N", "⌃+U", "⌃+B", "⇧+⌃+A", "⌃+A", "⌥+I", "⌥+O", "⇧+⌥+I", "⇧+⌥+O", "⌥+B", "⌥+D", "⌥+S", "⌃+⌥+M", "⌃+⌥+B", "⌃+⌥+X", "⇧+⌃+G", "⇧+⌃+⌥+R", "⇧+⌃+⌥+L", "⌃+Å", "⌃+]", "⇧+⌃+Å", "⇧+⌃+}", "⇧+⌃+M", "⇧+⌃+⌥+!", "⇧+⌃+⌥+@", "⇧+⌃+⌥+£", "⇧+⌃+⌥+$", "⇧+⌃+⌥+%", "⇧+⌃+⌥+^", "⌃+1", "⌃+2", "⌃+3", "⌃+4", "⌃+5", "⌃+6", "⇧+⌃+!", "⇧+⌃+\"", "⇧+⌃+#", "⇧+⌃+€", "⇧+⌃+%", "⇧+⌃+&", "K", "⌃+K", "⌃+V", "⇧+⌃+⌥+K", "A", "Y", "Z", "⇧+⌃+*", "⇧+⌃+⌥+*", "X", "⌃+,", "⌃+.", "⇧+⌃+;", "⇧+⌃+:", "⌃+P", "⇧+⌃+)", "⇧+⌃+?", "⌃++", "Space", "[", "]", "V", "L", "P", "S", "N", "Q", "O", "T", "E", "D", "W", "C", "F"}

我想在列表的每一项中搜索特定字符的出现,并在每一项中替换它们。

"⇧" replaced with "shift"
"⌃" replaced with "control"
"⌥" replaced with "option"
"⌘" replaced with "command" 
"⌫" replaced with "backspace"
"→" replaced with "arrow right"

等等,

我尝试修改列表中每个项目的以下代码重复,但我似乎只能在使用字符串时让它工作。

on findAndReplaceInText(theText, theSearchString, theReplacementString)
            set AppleScript's text item delimiters to theSearchString
            set theTextItems to every text item of theText
            set AppleScript's text item delimiters to theReplacementString
            set theText to theTextItems as string
            set AppleScript's text item delimiters to ""
            return theText
end findAndReplaceInText

如何查找和替换列表中的每一项?

尝试以下示例 AppleScript 代码:

set hotkeyShortcutList to {"$", "U", "J", "G", "R", "⇧+R", "⇧+Y", "⇧+G", "⇧+B", "⇧+P", "⇧+⌫", "⌃+M", "⌃+W", "⌃+S", "⌃+X", "⌃+C", "⌃+V", "⌃+N", "⇧+⌃+N", "⌃+U", "⌃+B", "⇧+⌃+A", "⌃+A", "⌥+I", "⌥+O", "⇧+⌥+I", "⇧+⌥+O", "⌥+B", "⌥+D", "⌥+S", "⌃+⌥+M", "⌃+⌥+B", "⌃+⌥+X", "⇧+⌃+G", "⇧+⌃+⌥+R", "⇧+⌃+⌥+L", "⌃+Å", "⌃+]", "⇧+⌃+Å", "⇧+⌃+}", "⇧+⌃+M", "⇧+⌃+⌥+!", "⇧+⌃+⌥+@", "⇧+⌃+⌥+£", "⇧+⌃+⌥+$", "⇧+⌃+⌥+%", "⇧+⌃+⌥+^", "⌃+1", "⌃+2", "⌃+3", "⌃+4", "⌃+5", "⌃+6", "⇧+⌃+!", "⇧+⌃+\"", "⇧+⌃+#", "⇧+⌃+€", "⇧+⌃+%", "⇧+⌃+&", "K", "⌃+K", "⌃+V", "⇧+⌃+⌥+K", "A", "Y", "Z", "⇧+⌃+*", "⇧+⌃+⌥+*", "X", "⌃+,", "⌃+.", "⇧+⌃+;", "⇧+⌃+:", "⌃+P", "⇧+⌃+)", "⇧+⌃+?", "⌃++", "Space", "[", "]", "V", "L", "P", "S", "N", "Q", "O", "T", "E", "D", "W", "C", "F"}

set processedShortcutList to {}
repeat with thisShortcut in hotkeyShortcutList
    set thisShortcut to my findAndReplaceInText(thisShortcut, "⇧", "shift")
    set thisShortcut to my findAndReplaceInText(thisShortcut, "⌃", "control")
    set thisShortcut to my findAndReplaceInText(thisShortcut, "⌥", "option")
    set thisShortcut to my findAndReplaceInText(thisShortcut, "⌘", "command")
    set thisShortcut to my findAndReplaceInText(thisShortcut, "⌫", "backspace")
    set thisShortcut to my findAndReplaceInText(thisShortcut, "→", "arrow right")
    set end of processedShortcutList to thisShortcut
end repeat

return processedShortcutList

on findAndReplaceInText(theText, theSearchString, theReplacementString)
    set AppleScript's text item delimiters to theSearchString
    set theTextItems to every text item of theText
    log theTextItems
    set AppleScript's text item delimiters to theReplacementString
    set theText to theTextItems as string
    set AppleScript's text item delimiters to ""
    return theText
end findAndReplaceInText

结果: {"$", "U", "J", "G", "R", "shift+R", "shift+Y", "shift+G", "shift+B", "shift+P", "shift+backspace", "control+M", "control+W", "control+S", "control+X", "control+C", "control+V", "control+N", "shift+control+N", "control+U", "control+B", "shift+control+A", "control+A", "option+I", "option+O", "shift+option+I", "shift+option+O", "option+B", "option+D", "option+S", "control+option+M", "control+option+B", "control+option+X", "shift+control+G", "shift+control+option+R", "shift+control+option+L", "control+Å", "control+]", "shift+control+Å", "shift+control+}", "shift+control+M", "shift+control+option+!", "shift+control+option+@", "shift+control+option+£", "shift+control+option+$", "shift+control+option+%", "shift+control+option+^", "control+1", "control+2", "control+3", "control+4", "control+5", "control+6", "shift+control+!", "shift+control+\"", "shift+control+#", "shift+control+€", "shift+control+%", "shift+control+&", "K", "control+K", "control+V", "shift+control+option+K", "A", "Y", "Z", "shift+control+*", "shift+control+option+*", "X", "control+,", "control+.", "shift+control+;", "shift+control+:", "control+P", "shift+control+)", "shift+control+?", "control++", "Space", "[", "]", "V", "L", "P", "S", "N", "Q", "O", "T", "E", "D", "W", "C", "F"}