How can I make an applescript that inserts an emoji into the focussed text field?
I tried
tell application "System Events" to keystroke "🐶" & return
but this puts in "aa" rather than the emoji I want.
You can't do that with keystroke.
Alternatively set the value of attribute AXSelectedText of the correspondent UI element to the character for example
activate application "TheApp"
tell application "System Events"
tell process "TheApp"
set value of attribute "AXSelectedText" of text field 1 of window 1 to "🐶"
keystroke return
end tell
end tell
You can determine the reference to the UI element with UIElementInspector or UI Browser.
Or use the clipboard:
set the clipboard to "🐶"
tell application "System Events"
keystroke "v" using command down
keystroke return
end tell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With