Safariウインドウ内のView部分を調べてみる。 [AppleScript辞書はつくれるか?]
tell application "Safari" set {x, y, w, h} to bounds of window 1 end tell |
tell application "Safari" --|Windowが一つも開いていなければ終了する処理| if (count of windows) = 0 then return false -- |最前面のWindowのDocumentが空の場合はサイズが測れない -- (そもそもView設定がされていない)ので、無理矢理に白ページをあてがう| if (source of document 1) = "" then set add to do shell script ("echo '' > $HOME/dammy.htm ; echo file:///$HOME/dammy.htm ;") set URL of document 1 to add delay 0.5 do shell script ("rm $HOME/dammy.htm ;") end if end tell
tell application "System Events" tell process "Safari" --ピンポピントでWebの表示部分の情報を取得 set obj to properties of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1 -- log obj --|どんな情報が取得できているかに興味がある人は、ここの左端のコメントアウトを外してみてください| set {x, y} to position of obj -- View部分の原点(左上の角の座標)の取得 set {w, h} to size of obj -- View部分の大きさを取得 end tell end tell
(* 取得した位置をポインターの移動で視覚的に確認 *) my movePointer(x, y) --|Viewの始点(原点)に移動| delay 2 my movePointer(x + w, y + h) --|Viewの終点に移動|
on movePointer(x, y) --|ポインターを移動のみするハンドラ| set codeText to "import sys; from Quartz.CoreGraphics import CGEventCreateMouseEvent,CGEventPost,CGPointMake; x = float(" & x & "); y = float(" & y & "); po = CGPointMake(x, y); event = CGEventCreateMouseEvent(None, 2, po, 0); CGEventPost(0, event);" do shell script "python -c " & quoted form of codeText return true end movePointer |
コメント 0