將文字寫入(「注入」)現有 Ubuntu 終端

將文字寫入(「注入」)現有 Ubuntu 終端

給出一個名字已經運行終端(gnome-terminal也許?),有沒有辦法從另一個程式寫入文字?

我基本上正在尋找一種從文字編輯器開始編譯的方法。

答案1

如果您沒有它們,請安裝xwininfo(在 x11-utils 套件中)並xvkbd

sudo apt-get install x11-utils
sudo apt-get install xvkbd

然後找到「受害者」視窗的視窗 ID:

xwininfo

遊標變成十字 --- 按一下要插入文字的 gnome 終端視窗。在訊息中,複製視窗id:

xwininfo: Please select the window about which you
      would like information by clicking the
      mouse in that window.

xwininfo: Window id: 0x1a005be "romano@samsung-romano: ~"
[...]

現在,您可以從另一個終端注入字元:

(0)samsung-romano:~% xvkbd -window 0x1a005be -text "ls -l\n"

\n如果您希望執行該命令,請記住)。

還有更多方法來識別窗口---看xvkbd 的手冊頁。其中一種方法是使用 XWindows 的「class」屬性。您可以使用您選擇的特定類別名稱來運行終端,例如:

xterm -class alfa & 

然後透過注入

xvkbd -window alfa -text "ls -l\n" 

(我xterm在這裡用過,我不能這樣做gnome-terminal——我不知道為什麼)。

相關內容