Thank you very much, @Mockman
It works! :-))
tell application "TextEdit" to activate
tell application "System Events"
keystroke return
key code 39 -- acute accent «´»
key code 0 -- letter «a»
--á
key code 39
key code 14 -- e
--é
key code 39
key code 34 -- i
--í
key code 39
key code 31 -- o
--ó
key code 39
key code 32 -- u
--ú
keystroke return & space
set str to "El último café cálido quedó frío" -- The last hot coffee remained cold
set the clipboard to str
keystroke (the clipboard as text) -- El altimo cafa calido queda frao (¡!)
-- This is one of the situations of interest is the handling of the clipboard with strings containing accented vowels.
-- Another is searching for accented words in the Finder search box.
keystroke return
keystroke "El "
key code 39
key code 32
keystroke "ltimo caf"
key code 39
key code 14
keystroke " c"
key code 39
key code 0
keystroke "lido qued"
key code 39
key code 31
keystroke " fr"
key code 39
key code 34
keystroke "o"
--result
--áéíóú
--El altimo cafa calido queda frao
--El último café cálido quedó frío
end tell
Now a new challenge arises: making use of it.
The practical problems are the use of the clipboard with words containing accented vowels, and especially when it is used to enter information in the Finder search box to perform searches. The results are disastrous because of the presence of characters that do not correspond to those desired.
How could it be made easier to use ? I did an exercise to print a string, (really heavy and painful); using a script based on “text item delimiters” it is possible to correct the strings.
This script removes from the clipboard the changes caused by the presence of accented vowels and allows you to continue working with the same vowels, but without accentuation.
on removeAccents(_str)
set oldDelims to AppleScript's text item delimiters
set listWithAccents to {"á", "é", "í", "ó", "ú", "Á", "É", "Í", "Ó", "Ú"}
set listWithoutAccents to {"a", "e", "i", "o", "u", "A", "E", "I", "O", "U"}
considering case --
repeat with i from 1 to count of listWithAccents
set AppleScript's text item delimiters to item i of listWithAccents
set theTextItems to text items of _str
set AppleScript's text item delimiters to item i of listWithoutAccents
set _str to theTextItems as string
end repeat
end considering
set AppleScript's text item delimiters to oldDelims
return _str
end removeAccents
A different question is to correct strings with accents, for example, when using the clipboard with them while writing a script.
Can you think of any suggestions?