set mouseToolsPath to "" & (path to home folder) & "UnixBins:MouseTools"
set {Xi, Yi} to {1550, 567}
(*
test 1 *)
set {X, Y} to paragraphs of (do shell script quoted form of POSIX path of mouseToolsPath & " -location")
log {X, Y}
(*291, 65*)
do shell script quoted form of POSIX path of mouseToolsPath & " -x " & (Xi as text) & " -y " & (Yi as text) & " -leftClick-leftClick"
set {X, Y} to paragraphs of (do shell script quoted form of POSIX path of mouseToolsPath & " -location")
log {X, Y}
(*1550, 567*)
set {X, Y} to {10, 10}
(*
test 2 *)
do shell script quoted form of POSIX path of mouseToolsPath & " -x " & (Xi as text) & " -y " & (Yi as text)
set {X, Y} to paragraphs of (do shell script quoted form of POSIX path of mouseToolsPath & " -location")
log {X, Y}
(*1550, 567*)
repeat 2 times
do shell script quoted form of POSIX path of mouseToolsPath & " -leftClick"
end repeat
Both of them correctly move the mouse but fail to issue the double click.
Hi Yvan. I updated the tool so download the new version v0.4 here. I added a double-click to it. The 2 single clicks weren’t working as you explained. The new switch is called -doubleLeftClick. Here’s a script. I hope this helps.
-- move the mouse to the x/y coordinates (as measured from the top-left part of the screen) and perform a mouse double-click with the left mouse button
set mouseToolsPath to (path to home folder as text) & "UnixBins:MouseTools"
set x to 300
set y to 300
do shell script quoted form of POSIX path of mouseToolsPath & " -x " & (x as text) & " -y " & (y as text) & " -doubleLeftClick"
Entering the download page, I saw that you didn’t update it about this new feature.
I guess that the duration between two clicks was too long.
I will test to-morrow because now, I’m too tired.
All day long I made a lot of tests trying to discover what I was doing wrongly
Why are you always explicitly coercing the parameters to text ?
As the beginning of the instruction is text, the concatenated numbers are automatically coerced as text.
You’re welcome. I did update the download page… you probably have to reload your browser.
Actually as I was testing my new code the double-click wasn’t working at first. It took me awhile to figure out the problem. I had to first issue a single click to bring the thing I was trying to click to the front, then the double-click worked. So my new code actually issues a single click and a double click.
After figuring this out it occurred to me that maybe the old code would have worked by issuing 3 clicks instead of 2. As explained, the first click to bring the thing to the front and then 2 more clicks for the double click. I didn’t check that though as I had already written the new code. Did you ever try that?
It’s just habit. I’d rather coerce things myself. It’s easier in my mind. If I’m concatenating strings then I make sure everything is a string and I don’t have to think about if the proper conversions will take place.
(1) here, applying leftClick three times doesn’t apply.
(2) During my tests, I have to apply to 15 items in a doc.
doubleClickLeft apply to items 1, 3, 5, 7, 9, 11, 13, 15
but fails for items 2, 4, 6, 8, 10, 12, 14
I solved the problem by a short delay inserted BEFORE the call.
Inserting the delay after the call changed nothing
Just for info, here is the draft of the script :
(*
This script change the size of formulas inserted by MathType in a Pages document.
The original size was 22 and the document's author wanted to reduce it to 12.
It requires :
Pages '09
MathType 6
and MouseTools version 0.4 available at :
http://www.hamsoftengineering.com/codeSharing/MouseTools/MouseTools.html
My script is free but it would be fair to donate some cash to HamSoft.
Yvan KOENIG (VALLAURIS, France)
2011/02/23
At this time,
the script treats only documents containing a single section.
it treat the case upon which I was asked.
The formulas are inline in the main text layer.
*)
property root_name : "image #"
property mouseToolsPath : ""
on run
set mouseToolsPath to "" & (path to home folder) & "UnixBins:MouseTools"
run script do_your_duty
set mouseToolsPath to "" (* Clears the property *)
end run
script do_your_duty
tell application "Pages" to tell document 1 to tell body text
set nb_images to count of (get every image)
set maybe to name of image 1
try
set nom1 to maybe
on error
set nom1 to ""
end try
if nom1 does not start with root_name then
repeat with i from 1 to nb_images
set name of image i to (root_name & i)
end repeat
end if
end tell -- Pages
tell application "Pages" to activate
tell application "System Events" to tell application process "Pages"
set frontmost to true
set list_of_inline_images to {}
tell (first UI element whose role is "AXLayoutArea") of first scroll area of first splitter group of window 1
set nb_pages to count of group
repeat with page_index from 1 to nb_pages
tell first text area of group page_index
set nb_images to count of every image
repeat with image_index from 1 to nb_images
tell image image_index to copy {page_index, image_index} to end of list_of_inline_images
end repeat -- with image_index
end tell -- first text area
end repeat -- page_index
end tell
end tell
tell application "Pages" to tell document 1 to tell body text
set nb_images to count of (get every image)
repeat with i from 1 to nb_images
select image i
my resize_inline_image(get item i of list_of_inline_images)
end repeat
end tell
(*
Ready for future treatment of floating images
*)
tell application "Pages" to tell document 1
set nb_pages to count of pages
repeat with page_index from 1 to nb_pages
set nb_images to count of images of foreground layer of page page_index
if nb_images > 0 then
repeat with image_index from 1 to nb_images
--
end repeat -- image_index
end if
end repeat -- page_index
end tell
end script
--=====
on resize_inline_image({page_num, image_num})
tell application "Pages" to activate
tell application "System Events" to tell application process "Pages"
set frontmost to true
tell (first UI element whose role is "AXLayoutArea") of first scroll area of first splitter group of window 1
tell image image_num of first text area of group page_num
set {{Xleft, Ytop}, {w, h}} to get {position, size}
end tell -- image
end tell -- layout
end tell -- System events
set {Xi, Yi} to {Xleft + (w div 2), Ytop + (h div 2)}
(*
tell application "Extra Suites"
ES move mouse {Xi, Yi}
ES click mouse with double click
end tell
*)
delay 0.1 -- REQUIRED HERE
do shell script quoted form of POSIX path of mouseToolsPath & " -x " & Xi & " -y " & Yi & " -doubleLeftClick"
(*
do shell script quoted form of POSIX path of mouseToolsPath & " -x " & (Xi as text) & " -y " & (Yi as text)
repeat 3 times
do shell script quoted form of POSIX path of mouseToolsPath & " -leftClick"
end repeat
*)
try
tell application "MathType" to activate
tell application "System Events" to tell application process "MathType"
tell menu bar 1 to tell menu bar item 8 to tell menu 1 to click menu item 14
repeat with yk from 1 to 5
try
if title of window 1 is "Define Sizes" then exit repeat
end try
delay 0.1
end repeat
if yk < 5 then
keystroke "12" & return
keystroke "w" using {command down}
repeat until title of window 1 is "MathType"
delay 0.1
end repeat
keystroke return
end if
end tell
end try
end resize_inline_image
--=====
delay 0.1 -- REQUIRED HERE
do shell script quoted form of POSIX path of mouseToolsPath & " -x " & Xi & " -y " & Yi & " -doubleLeftClick"
For se, I edited it this way :
do shell script quoted form of POSIX path of mouseToolsPath & " -x " & Xi & " -y " & Yi
do shell script quoted form of POSIX path of mouseToolsPath & " -doubleLeftClick"
The mouse correctly entered the selected target but only odd (uneven) calls really applied the double click.