バッチファイルとQuick Macrosの組み合わせを使用してプログラムを作成しようとしましたが、私の母国語(チェコ語)のテキストに分音が自動的に追加されています。 私はすべてが機能しています。ユーザが画面 特定の文字セットを使用してテキストをクリップボードにコピーする方法
- )
- 応答は、応答ファイル
- に格納されているのと同じバッチスクリプトは 固定テキスト を取得するには、応答ファイルをトリミング
- を別のファイルに保存します。
ここでは問題が発生しています。チェコ語の発音記号はISO-8859-2文字セットを使用しますが、ファイル内容をコピーするとANSIエンコーディングが得られ、ユーザーの元の選択テキストを置き換えるために貼り付けられたときにアクセント付き文字が破棄されます。
QMにメモ帳++のインスタンスを開き、手動でメニューを操作して文字セットを変更した後、テキストを選択してコピーし、メモ帳++を閉じることで回避します。
これは非常に洗練されていないため、スクリプトを実行するたびに画面上にウィンドウが表示され、実行時間の約80%を占めるアカウントを待っています。
特定の文字セットを使用してテキストファイルからクリップボードにテキストを取得する方法を知っている人はいますか?バッチやパワーシェルを使用するのが望ましいですか? (私はそれが既に正しい文字セットで表示されている間にコピーされていればうまくいくことを知っています。
すべての私のコード:
QMキーボードショートカットによってトリガ(乱雑に見えるビットが、すべての行をコメント化されている)
/create variable 's' and copy current selection to it
str s.getsel;
/if nothing was selected, the program ends
if (empty(s))
end
/remember which window the selection is from
int orWin = win
/create "params.txt" from content of 's'
s.setfile("D:\AppData\Local\CZaccent\params.txt");
/wait until "params.txt" is created (yes, this is the right way to do it)
rep
if(FileExists("D:\AppData\Local\CZaccent\params.txt")) break
/run "endline_purge.bat" minimised
run "D:\AppData\Local\CZaccent\endline_purge_min";
/wait for "endling_purge.bat" to close (any command window being destroyed triggers this)
wait -1 WD win("C:\Windows\System32\cmd.exe");
/copy new content of "params.txt" to variabel 's'
s.getfile("D:\AppData\Local\CZaccent\params.txt");
/remove "params.txt"
del- "D:\AppData\Local\CZaccent\params.txt";
/run "request.bat" minimised, passing 's' as arguments
run "D:\AppData\Local\CZaccent\request_min" s;
/wait for "request.bat" to close
wait -1 WD win("C:\Windows\System32\cmd.exe");
/remove "response.html"
del- "D:\AppData\Local\CZaccent\response.html"
/open "output.txt" (created by "request.bat") in Notepad++
run "C:\Program Files\Notepad++\notepad++.exe" "D:\AppData\Local\CZaccent\output.txt"
/wait for Notepad++ to open
wait -1 WA win("D:\AppData\Local\CZaccent\output.txt - Notepad++" "Notepad++")
/use shortcut keys to select ISO-8859-2 charset
'An cY eY
/if a dialog opens, confirm it (error occurs if it is not open)
act(win("Save Current Modification"))
err goto search_cont
'Y
search_cont
/select all
'Ca
/copy selection to 's'
s.getsel
/close Notepad++
clo
/delete "output.txt"
del- "D:\AppData\Local\CZaccent\output.txt"
/restore the original window where selection is active
act(orWin)
/trim trailing endline from 's' (13=CR 10=NL)
str CRNL.format("%c%c", 13 10)
s.rtrim(CRNL)
/paste content of 's' (into the active selection, replacing it)
'(s)
endline_purge.bat
@echo off
setlocal EnableDelayedExpansion
set "line="
for /F "delims=" %%a in (params.txt) do set "line=!line!\n%%a"
echo !line:~2!>params.txt
request.bat(また、HTML応答から不要なコンテンツをトリミング)
@echo off
call "C:\Program Files\cURL\curl.exe" --data "text=%*" https://nlp.fi.muni.cz/cz_accent/ > D:\AppData\Local\CZaccent\response.html
SETLOCAL ENABLEDELAYEDEXPANSION
set content=
for /f "delims=" %%i in (response.html) do set content=!content! %%i
set content=!content:~391,-993!
echo !content:^<p^> =^
! > output.txt
codepage__を__changeするコマンドは 'chcp'です。コマンドプロンプトウィンドウで任意のパラメータを指定せずに 'chcp'を実行すると、コンフィグレーションされた領域に応じてユーザアカウントのコンピュータ上でデフォルトで定義されているコードページが表示されます。あなたのバッチファイルの先頭に 'chcp 1250'を使用することは、あなたの仕事のための正しいコマンドかもしれません。 – Mofi
私はchcp 852(slavic)を追加しようとしましたが、コンソールはまだ間違った文字セットをクリップボードに出力します。何も変わっていないようです。 – totalolage
は、iso-8859-2用のchcp 28592を発表しました!本当にありがとう! – totalolage