以前書いた正規構文の構文がAppleScriptで希望の動作をしないので、Jeditで動作確認をしてみると、
^[ \\t]*[\\r\\n]+→^\s+
としても、空白行が削除されず変化がありませんでした。
短いコードの方がチェックも楽ですから、同じ機能だったらこちらの方がいいかもしれません。
内容は、行の先頭に空白が一回以上連続したものを、完全なカラ””で置き換える。というものです。
そこでせっかく作ったScriptで空白行が削除されないのは残念ですので、ちょっと検討してみました。
コードの可読性がいいように、一つの構文ごとにコメント文で区切ることにしました。
冗長で最初に手間がかかりますが、後で楽です。
正規表現は私にとって悪魔ならぬ魔法の呪文です。
--最初に処理すべきところをコピーしておく。コピー忘れを防ぐために実際には警告ウインドウを表示している。
--────────エラー回避のために最初にJeditを起動
tell application "Jedit X"
activate
delay 2.0
end tell
--──────────
------------------起動チェック終了
set paraNum to 0
set danraku to "/Users/操作対象ファイル.txt" as POSIX file
tell application "Finder"
open danraku
delay 3.0
tell document 1
tell application "System Events"
--delay 0.5
keystroke ":" using {control down, shift down} --お決まりの英字入力(ここが;でエラー)
keystroke ":" using {control down, shift down} --半角になってしまうので二回2013/01/24
keystroke "v" using {command down, shift down} --スタイルなしペースト
------------------空白行削除に成功したスクリプト
tell application "Jedit X"
tell front document
--2017/06/16 正規表現を訂正^[ \\t]*[\\r\\n]+→^\s+
--2017/06/16 カギカッコつけるべきか?
--2017/06/16 空白行が消えないのでに\\sにカギカッコつけてみる。
replaceAll string "^\\s+" to "" with select all, case sensitive, grep and entire word
--replaceAll string "" to "" with select all, case sensitive, grep and entire word --を削除
end tell
end tell
------------------空白行削除おわり
------------------</p>タグを行末に挿入
keystroke "t" using {shift down, control down} --プレーンテキストに。スタイルなしペーストだからいらないかも。
keystroke "f" using command down --検索ウインドウを開く
key code 51 --デリート以前入力してた文字が有るかもしれないので。
keystroke "$" --行末を指定
keystroke tab --入力ウインドウの移動
key code 51 --デリート
keystroke "</p>" --</p>タグを入れる
keystroke "w" using command down --検索ウインドウを閉じる
keystroke "a" using command down --すべてのテキストを選択
keystroke "r" using {command down, shift down} --置換
------------------挿入終わり
------------------<p>タグを行頭へ挿入
keystroke "f" using command down --再度検索ウインドウを開く
key code 51 --デリート
keystroke "^" --行頭
keystroke tab --入力ウインドウの移動
key code 51 --デリート
keystroke "<p>" --<p>タグ >
keystroke "w" using command down --検索ウインドウを閉じる
keystroke "a" using command down --すべてのテキストを選択
keystroke "r" using {command down, shift down} --置換
------------------挿入終わり
------------------不要な<p></p>タグを取る。2017/02/10
keystroke "f" using command down --再度検索ウインドウを開く
key code 51 --デリート
keystroke "<p></p>" --いらない部分(半角挟まないとき)
keystroke tab --入力ウインドウの移動
key code 51 --デリート
--keystroke "" --ヌルを入れる。上とおなじく。
keystroke "w" using command down --検索ウインドウを閉じる
keystroke "a" using command down --すべてのテキストを選択
keystroke "r" using {command down, shift down} --置換
------------------<p></p>タグ取る終わり
------------------プレーンテキスト化後に残った<p> </p>タグを削除
tell application "Jedit X" tell front document replaceAll string "^\\s+" to "" with select all, case sensitive, grep and entire word
end tell
end tell
------------------<p> </p>タグを削除した後の空白行を削除終わり
delay 0.5
keystroke "a" using command down
keystroke "x" using command down
--テキストをカット
keystroke "w" using command down --ウインドウを閉じる
keystroke return --空白で保存
end tell
end tell
end tell
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
