We recently moved from RHEL 8.4 CLI to RHEL8.8 GUI Terminal interface. In doing so my TypeText commands have stopped typing the correct characters i.e. if I type “A” I might get “a” or “(” will get “9”. It does not happen consistently the same all the time. The following snipet of code fails to type the correct values.
set tempWord to “echo ‘Hello World’ | grep ‘Hello’;s=$(echo ‘Hello World’ | grep -c ‘Hello’);[[ $s -gt 0 ]] && echo ’ CONNECTION’‘FOUND’ || echo ’ NOT’‘FOUND’”
MyTypeText tempWord
to handle MyTypeText
params ToType
set characterSet to <<!@#$%^&*()_+QWERTYUIOP{}|}ASDFGHJKL:"ZXCVBNM<>?>>
set localKeyDownDelay to 0.3 -- try different values here
set localNextKeyDelay to 0.1
repeat with charItem = each char of ToType
wait localNextKeyDelay
if characterSet contains charItem considering case
typeText ShiftKey, charItem
else
typeText charItem
end if
//typetext theKey -- press the key
wait localKeyDownDelay
end repeat
end MyTypeText
After more testing, it appears that I get more consistency by changing my delay tactics to nextKeyDelay. With this value set to .05 it failed about 60% of the time. At .08 seems to be working 100% of the time, but test set is still small.
To speed up this script I have minimized the number of characters that need a “shiftKey” in front of them and I have grouped them so that the typeText can type them faster. Lastest iteration of the script.
set printWord to ""
set nKD to getOption (nextKeyDelay)
// setOption nextKeyDelay, .05
put each character of "echo 'Hello World' | grep 'Hello';s=$(echo 'Hello World' | grep -c 'Hello');[[ $s -gt 0 ]] && echo ' connection''found' || echo ' not''found'" into tempCharSet
set characterSet to <<!@#$%^&*()_+QWERTYUIOP{}|}ASDFGHJKL:"ZXCVBNM<>?>>
repeat for each charItem of tempCharSet
if characterSet contains charItem considering case
setOption nextKeyDelay, nKD
TypeText printWord
setOption nextKeyDelay, .08
TypeText ShiftKey, charItem
set printWord to ""
else
put charItem after printWord
end if
end repeat
setOption nextKeyDelay, nKD
TypeText printWord,returnKey
End repeat