Reputation: 21
Trying to map a remote so I can use it to manipulate my music software, and to do this I want to be able to move the mouse around and click it. All the solutions I've found (e.g. MouseTools, AppleScript built-in click functions, Apple's Accessibility "MouseKeys" click-to-key function) seem to be overly fussed about layers, windows etc, trying to funnel the click to the application and ask what it wants to do about it. One AppleScript error proclaimed "Failed to click."
My question is, what's a Terminal command/AppleScript function I can use to do a simple, normal click as though I had done it from the trackpad - as in, it bloody clicks, without caring what's beneath, but just does it and processes the consequences (opens window, selects window, anything, I don't care but I just want it to normally click as though it were actually a physical trackpad click).
I'm tearing my hair out over this because it seems that Apple has tried to prevent any software solution from doing anything that might come close to an actual global click. Any solutions? Thanks :)
Upvotes: 1
Views: 7126
Reputation: 3142
I would suggest downloading AppleScript toolbox scripting addition. Once installed in the proper locations, in Script Editor.app, , you will be able to use commands from the key and mouse suite from the AppleScript toolbox dictionary to…get, set, and click at mouse locations (coordinates)
Here is some sample code using commands from the AppleScript toolbox dictionary
EXAMPLE 1
set mousePointLocation1 to {745, 110} -- The Collapsed Menu
set mousePointLocation2 to {780, 340} -- TV Link In The Menu
set mousePointLocation3 to {885, 180} -- Apple TV 4K Icon
delay 1 -- For Demonstration Purposes
activate application "Safari"
delay 1 -- For Demonstration Purposes
AST click at mousePointLocation1 ¬
number of clicks 1
delay 1 -- For Demonstration Purposes
AST click at mousePointLocation2 ¬
number of clicks 1
delay 1 -- For Demonstration Purposes
AST click at mousePointLocation3 ¬
number of clicks 1
EXAMPLE 2
-- For Demonstration Purposes
-- Gives Me Time To Put The Mouse Where I Want
delay 3
-- Gets Coordinates Of The Current Mouse Location
set currentMouseLocation to AST mouse point location
-- Mouse Click At Defined Location
AST click at currentMouseLocation ¬
number of clicks 2 -- How Many Clicks
EXAMPLE 3
set mousePointLocation to {20.0, 20.0}
delay 1 -- For Demonstration Purposes
AST set mouse point location mousePointLocation ¬
without holding mouse down
delay 1 -- For Demonstration Purposes
AST click at mousePointLocation ¬
number of clicks 1
Upvotes: 1