Safariのスクロールバーをコントロールしたい [AppleScript辞書はつくれるか?]
Safariで表示されているページで、見える部分の外にも情報がある場合にスクロールバーが追加されます。
そのスクロールバーのマーカーの位置が知りたい。または、マーカーの位置を移動したいという場合に、Applescriptでは命令文が存在しなかったので、なんとかしてみたいと思いました。
System EventsのUI elementを調べていけばわかると思い、膨大な情報の中から検索してみたら有りました。
scroll bar 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1
または、
scroll bar 2 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1
"scroll bar 1"が横のバーで、"scroll bar 2"が縦のバーかと思ったらそうでもなかったみたいで、どちらかが非表示だった場合は、どちらでも"scroll bar 1"になるようでした。
ですので、非表示を含めちゃんとした情報を取得して横か縦かを判断して振り分けてみます。
(* Safariのスクロールバー情報の取得 *) tell application "System Events" tell process "Safari" set objList to every scroll bar of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1 set {scrollBarVertical, scrollBarHorizontal} to {missing value, missing value} repeat with scrollBar in objList set ans1 to properties of scrollBar set ans2 to orientation of ans1 if ans2 = "AXVerticalOrientation" then set scrollBarVertical to ans1 else if ans2 = "AXHorizontalOrientation" then set scrollBarHorizontal to ans1 end if end repeat end tell end tell log "縦の結果" log scrollBarVertical log "横の結果" log scrollBarHorizontal |
(*縦の結果*) (*class:scroll bar, minimum value:missing value, orientation:AXVerticalOrientation, position:910, 438, accessibility description:, role description:スクロールバー, focused:false, title:, size:15, 561, help:, entire contents:, enabled:true, maximum value:missing value, role:AXScrollBar, value:0.0, subrole:missing value, selected:false, name:missing value, description:*) (*横の結果*) (*class:scroll bar, minimum value:missing value, orientation:AXHorizontalOrientation, position:109, 999, accessibility description:, role description:スクロールバー, focused:false, title:, size:801, 15, help:, entire contents:, enabled:true, maximum value:missing value, role:AXScrollBar, value:0.0, subrole:missing value, selected:false, name:missing value, description:*) |
バーの現在の位置は、
value of scrollBarVertical
で値が取得でき、移動の場合は、
set value of scrollBarVertical to 0.5
で変更ができます。
この時の値は、移動可能領域の『いちばん上』または『左端』が「0.0」となり、
終点の『下』または『右端』は1.0となっているようです。
まぁ、いったいこれが何に使えるかは考えておりませんが...。
コメント 0