Extension for GoldenDict-ng

Hi … Can you add an option to translate by GoldenDict-ng app.

#popclip 
name: GoldenDict
icon: circle filled GD
before: copy
applescript: |
  tell application "GoldenDict-ng"
     launch
     activate
  end tell
  tell application "System Events"
  delay 2
  key code 55 & 9
  key code 36
  end tell

I’m using a PopClip snippet I made to search for words in GoldenDict. It works perfectly the first time: the selected word is entered into GoldenDict’s search field, and the definition appears. But there’s a trouble, that is, on subsequent searches, the previously searched word remains in the search field, although the definition for the new word still shows up in the main GoldenDict window. So, the lookup works, but the word isn’t being populated in the search box after the initial use.

New Update

Sometimes the previous snippet doesn’t work properly because pressing the tab key sequentially cycles through the three elements on the screen. To solve this problem, I changed it to focus on the input field using a shortcut. This seems to be the most stable for now.

#popclip 
name: GoldenDict
icon: circle filled GD
before: copy
applescript: |
  tell application "GoldenDict-ng"
    if not running then
      launch
      activate
       repeat until application "GoldenDict-ng" is frontmost
        delay 0.1
      end repeat
      delay 2
    else
      activate
    end if
  end tell
  tell application "System Events"
    tell process "GoldenDict-ng"
      if frontmost is false then
        set frontmost to true
      end if
     key code 53
     key code 55 & 9
     key code 36
    end tell
  end tell