
シェル スクリプト経由で強調表示されたテキストにアクセスすることは可能ですか?
強調表示されたテキストを読むために「espeak」を使用するキーボードショートカットを作成したいと思います。
答え1
はい、これは比較的簡単です。クリップボードを操作するツールはたくさんあります。私は、Apple デバイスの登録やメールの確認にそれらを使用しました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 文字列として読み取ります。ただし、これは特殊なケースです。
もちろん、一部のアプリケーションはクリップボードにコピーしますが (FAQ を参照)、すべてではありません。たとえば、rxvt などはプライマリ選択を使用します。どこでも機能するソリューションはありません。
参考文献: