I'm trying to edit a list of shortcuts and separate keys with a "+" character.
So "⌃⌥B" becomes "⌃+⌥+B" and so on
So far I've been able to extract my shortcuts into a list named "hotkeyShortcutList".
My example hotkeyShortcutList list looks like this:
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"}
My script for processing so far:
set processedShortcutList to {}
repeat with i from 1 to length of hotkeyShortcutList
set theCurrentListItem to item i of hotkeyShortcutList
set processedListItem to (do shell script ("<<<" & theCurrentListItem & " sed -E 's/.{1}/&+/g ; s/-$//'"))
set processedListItem to characters 1 thru -2 of processedListItem as text
set end of processedShortcutList to processedListItem
end repeat
return processedShortcutList
However I've got 3 issues:
The shell script seems to work on regular characters, but bugs out when trying to handle special characters like "⇧", "⌃" and "⌥". I have very limited understanding of shell scripts, but it seemed to be the way to go with text handling from what I could Google...
I need to replace special characters with text after the "+"'s have been added. ⇧ replaced with "shift", ⌃ replaced with "control", ⌥ replaced with "command", ⌥ replaced with "command" etc.
I'd like to add some edge case protection to keys that have multiple letters like "space" for spacebar and "F1" for F-keys, so I don't end up with "s+p+a+c+e" and "F+1".
I know AppleScript might not be the easiest way to do it, but I'll be using the values inside of an AppleScript, so I feel like it would be nice to keep it all together. Any suggestions?