Validation Serviceを実行

テキストエディタ“mi”で表示中のドキュメントを取得し、
「The W3C Markup Validation Service」のインプット画面に入力。チェックを実行するスクリプトです。
スクリプト単体で実行しても動作しますが、miのツールに登録するとメニューから実行でき便利です。
しかし完璧なものではなくて、チェックするものによって入力がうまくいかず空欄のまま実行されエラーになるケースもあります。
原因は調査中ということで..

2022年01月14日 バージョン2を追加しました。
ちょっと力業ですけど、実行結果が空になった場合cliclickを使ってテキストエリアをクリックして、クリップボードにコピーした内容を貼り付け、チェックを実行します。

2023年02月01日 バージョン3を追加しました。

tell application "mi"
set aCon to content of front document
end tell

tell application "Safari"
launch
activate
make new document with properties {URL:"https://validator.w3.org"}
delay 0.4

set theSource to ""
repeat until theSource contains "</html>"
delay 0.2
set theSource to get the source of front document as string
end repeat

tell application "System Events"
launch
tell process "Safari"
set frontmost to true
try
tell window "The W3C Markup Validation Service"
click group 3 of group 2 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1
delay 0.8
tell group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1
tell application "Safari"
activate
do JavaScript "document.getElementById('fragment').value = `" & aCon & "`;" in front document
end tell
delay 0.8
click UI element "Check"
end tell
end tell
end try
end tell
end tell
end tell
バージョン2
tell application "mi"
set aCon to content of front document
end tell

tell application "Safari"
launch
activate
make new document with properties {URL:"https://validator.w3.org"}
delay 1

set theSource to ""
set break to 0
repeat
delay 0.5
set theSource to get the source of front document as string
delay 0.5
set break to break + 1
if break > 100 then
beep
return
end if
if theSource contains "</html>" then
exit repeat
end if
end repeat

tell application "System Events"
launch
tell process "Safari"
set frontmost to true
try
tell window "The W3C Markup Validation Service"
click group 3 of group 2 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1
delay 1.2
tell group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1
tell application "Safari"
activate
do JavaScript "document.getElementById('fragment').value = `" & aCon & "`;" in front document
end tell
delay 0.8

--------------------
tell application "Safari"
activate
if (do JavaScript "document.getElementById('fragment').value" in front document) = "" then
set the clipboard to aCon
delay 0.4
tell application "System Events"
launch
tell process "Safari"
try
tell text area 1 of group 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "The W3C Markup Validation Service"
set {xPosition, yPosition} to position
set {xSize, ySize} to size
end tell
-- modify offsets if hot spot is not centered:
do shell script "/usr/local/bin/cliclick c:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2)
delay 0.3
on error msg
display alert msg
return
end try
click menu item "ペースト" of menu 1 of menu bar item "編集" of menu bar 1
end tell
end tell
end if
end tell
--------------------

click UI element "Check"
end tell
end tell
end try
end tell
end tell
end tell
バージョン3
set cliclick to POSIX path of (path to resource "cliclick")

tell application "mi"
set aCon to content of front document
end tell

tell application "Safari"
activate
make new document with properties {URL:"https://validator.w3.org"}
delay 0.2
repeat 100 times
tell front document
set docName to name
delay 0.5
if docName = "The W3C Markup Validation Service" then
exit repeat
end if
end tell
end repeat
repeat 100 times
tell front document
set theSource to get the source
delay 0.5
if theSource contains "</html>" then
exit repeat
end if
end tell
end repeat

tell application "System Events"
--launch
tell process "Safari"
set frontmost to true
try
tell window "The W3C Markup Validation Service"
click group 3 of group 2 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1
delay 1.2
tell group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1
tell application "Safari"
activate
do JavaScript "document.getElementById('fragment').value = `" & aCon & "`;" in front document
end tell
delay 0.8

--------------------
tell application "Safari"
activate
if (do JavaScript "document.getElementById('fragment').value" in front document) = "" then
set the clipboard to aCon
delay 0.4
tell application "System Events"
--launch
tell process "Safari"
try
tell text area 1 of group 1 of group 3 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window "The W3C Markup Validation Service"
set {xPosition, yPosition} to position
set {xSize, ySize} to size
end tell
-- modify offsets if hot spot is not centered:
do shell script (quoted form of cliclick) & " c:" & xPosition + (xSize div 2) & "," & yPosition + (ySize div 2)
delay 0.3
on error msg
display alert msg
return
end try
click menu item "ペースト" of menu 1 of menu bar item "編集" of menu bar 1
end tell
end tell
end if
end tell
--------------------

click UI element "Check"
end tell
end tell
end try
end tell
end tell
end tell

更新履歴

inserted by FC2 system