Applescripting, move mouse and click by pushing one button?

Joined
Jun 3, 2011
Messages
4
Reaction score
0
Points
1
this is what i wanted to do:
When executing the script, a dialog comes up with the question: start script? when pressing "ok" the script will run. (easy)
I want to make the script do the following thing:
Absolutely nothing untill i press the key "K" on my keyboard. then it will move the mouse to a specific area of the screen, in my case (320, 250) (top left to bottom right X, Y).
So i came up with the following script:

set answer to button returned of (display dialog "start script?" buttons {"start script", "quit"} default button 1)
if answer is "start script" then
repeat
tell application "System Events"
try
tell application "KeyboardViewerServer" to activate
set shift1 to (get value of checkbox "K" of front window of application process "KeyboardViewerServer") as boolean
if shift1 is true then
move mouse {320, 250}
end if
end try
end tell
end repeat
end if
but It doesnt do what i want it to do. apparently the "keyboardviewerserver" app cant recognize the key "K" when other keys are pressed at the same time, and i DO want it to be able to do that. Also, when i try to use the command "click mouse" after "move mouse {320, 250}" the whole script FLIPS and starts randomly clicking and moving the mouse, and the script editor crashes.

Someone please help me? i really need to finish this script fast.

Thanks,

Timen Dillema.
 
Joined
May 19, 2009
Messages
8,428
Reaction score
295
Points
83
Location
Waiting for a mate . . .
Your Mac's Specs
21" iMac 2.9Ghz 16GB RAM - 10.11.3, iPhone6s & iPad Air 2 - iOS 9.2.1, ATV 4Th Gen tvOS, ATV3
Joined
May 14, 2009
Messages
2,052
Reaction score
136
Points
63
Location
Near Whitehorse, Yukon
Your Mac's Specs
2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
I would use Download Spark for Mac - Hotkey shortcuts manager. MacUpdate.com to run just the click portion of your script when a certain keystroke is typed.

clicking could also be like this, you could skip the whole move mouse thing.

Code:
tell application "System Events"
    tell application process "Safari"
        click (click at {650, 730})
    end tell
end tell
 
OP
T
Joined
Jun 3, 2011
Messages
4
Reaction score
0
Points
1

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top