從腳本訪問突出顯示的文字?

從腳本訪問突出顯示的文字?

是否可以透過 shell 腳本存取突出顯示的文字?

我想創建一個鍵盤快捷鍵來使用“espeak”來閱讀突出顯示的文字。

答案1

是的,這相對容易,有很多用於剪貼簿操作的工具,我用它們來填寫蘋果設備註冊和電子郵件驗證以及xdotool......比填寫 1000 次表格容易得多......

因此,設定一個快捷方式是/home/bob/bin/speak.sh

speak.sh:

#!/bin/bash

xclip -o | xclip -selection clipboard -i
xclip -o | espeak

答案2

簡短:通常您不能執行此操作(除非將選擇內容複製到剪貼簿)

long:有一些特殊情況,例如,xterm 有一個功能(通常被禁用)允許應用程式透過轉義序列讀取所選文字。這是在XTerm 控制序列:

        Ps = 5 2  -> Manipulate Selection Data.  These controls may
      be disabled using the allowWindowOps resource.  The parameter
      Pt is parsed as
           Pc; Pd
      The first, Pc, may contain zero or more characters from the
      set c  p  s  0  1  2  3  4  5  6  7 .  It is used to construct
      a list of selection parameters for clipboard, primary, select,
      or cut buffers 0 through 7 respectively, in the order given.
      If the parameter is empty, xterm uses s 0 , to specify the
      configurable primary/clipboard selection and cut buffer 0.
      The second parameter, Pd, gives the selection data.  Normally
      this is a string encoded in base64.  The data becomes the new
      selection, which is then available for pasting by other appli-
      cations.
      If the second parameter is a ? , xterm replies to the host
      with the selection data encoded using the same protocol.
      If the second parameter is neither a base64 string nor ? ,
      then the selection is cleared.

也就是說,如果允許視窗操作資源已啟用,應用程式可以執行類似的操作

printf '\033]52;s;?\007'

並將選擇資料讀取為 base64 字串。但這是一個特殊情況。

當然,某些應用程式會複製到剪貼簿(請參閱常見問題),但並非全部。例如rxvt等,使用首選。沒有一種解決方案在任何地方都適用。

延伸閱讀:

相關內容