I didn’t found floating graphic location in GUIScripting but I found a way to calculate this location with a mix of plain AppleScript and GUIScripting.
Here is my code :
(*
Requires MouseTools version 0.4 available at :
http://www.hamsoftengineering.com/codeSharing/MouseTools/MouseTools.html
It would be fair to donate some cash to HamSoft.
Yvan KOENIG (VALLAURIS, France)
2011/03/02
*)
set mouseToolsPath to "" & (path to home folder) & "UnixBins:MouseTools"
tell application "Pages" to tell document 1
set view_scale to (view scale of its window) / 100
reveal page 1
set {Page_left, Page_top} to my get_page_location()
end tell
(*
Here do what you want
*)
set page_num to 4
set image_num to 1
tell application "Pages" to tell document 1
tell page page_num
reveal it
tell graphic image_num to set {Hpos, Vpos, w, h} to {horizontal position, vertical position, width, height}
end tell
end tell
set {Xtarget, Ytarget} to {round (Page_left + Hpos * view_scale) rounding up, round (Page_top + Vpos * view_scale) rounding up}
(*
Trigger mouseTools to double click (and select) the graphic object *)
delay 0.1 -- may be REQUIRED HERE
do shell script quoted form of POSIX path of mouseToolsPath & " -x " & Xtarget & " -y " & Ytarget & " -doubleLeftClick"
--=====
on get_page_location()
tell application "Pages" to activate
tell application "System Events" to tell application process "Pages"
set frontmost to true
tell last scroll area of first splitter group of window 1
try
(*
Try to grab properties of horizontal ruler *)
tell (first UI element whose role is "AXRuler") to set {{HR_left, HR_top}, {HR_width, HR_height}} to get {position, size}
try
(*
Try to grab properties of vertical ruler *)
tell (last UI element whose role is "AXRuler") to set {{VR_left, VR_top}, {VR_width, VR_height}} to get {position, size}
on error
set {{VR_left, VR_top}, {VR_width, VR_height}} to {{0, 0}, {0, 0}}
end try
on error
set {{VR_left, VR_top}, {VR_width, VR_height}} to {{0, 0}, {0, 0}}
set {{HR_left, HR_top}, {HR_width, HR_height}} to {{0, 0}, {0, 0}}
end try
if {{VR_left, VR_top}, {VR_width, VR_height}} is {{0, 0}, {0, 0}} then
(*
No vertical ruler , full page left edge is the layout one *)
tell (first UI element whose role is "AXLayoutArea") to set {X_left, Y_top} to get position
else
(*
full page left edge is the vertical ruler's right one. *)
set X_left to VR_left + VR_width
end if
if {{HR_left, HR_top}, {HR_width, HR_height}} = {{0, 0}, {0, 0}} then
(*
No vertical ruler, full page top edge is the vertical scroll bar top one *)
tell scroll bar 2 to set {bof, Y_top} to get position
else
(*
full page top edge is the vertical ruler top one *)
set Y_top to VR_top
end if
end tell -- layout
end tell -- System Events
return {X_left, Y_top}
end get_page_location
Yvan KOENIG (VALLAURIS, France) mercredi 2 mars 2011 18:33:20