Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert emoji into focused text input

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.


1 Answers

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
like image 186
vadian Avatar answered Sep 18 '26 16:09

vadian