Actions conditional on mouse location


#1

My wife is significantly visually impaired.
We have 3 monitors and she is constantly "loosing" the mouse pointer.

I set up a simple macro for her that highlights the screen position for her with a touchpad gesture. It helps, but sometimes she still isn't able to find it across the monitors quick enough before the highlight goes away.

What I'd like to do is ad an audio que for her based on the mouse position.
What I have in mind is...
1 - grab screen# of the mouse current position.
2 - Play sound 1 if scren#1, sound 2 if screen#2, sound 3 if screen#3
3 - highlight mouse position.

I've got that third step figured out, but haven't been able to figure out steps 1 and 2.

Not sure how to grab the screen the mouse is on rather than just absolute position.


#2

Assuming your Main monitor is in the middle, and has a horizontal resolution of 1920, the following would work:

image


#3

Awesome. Thanks.


#4

You know about the modern Mac “shake to show mouse” feature?

I use that myself regularly when I lose the mouse, though even then it is not always obvious.

You can simplify @ScottinPollock’s solution a little by using the MOUSEX function. It is also wise to use the SCREEN functions. So Calculation conditions like:

MOUSEX() < SCREEN(Main,Left)
MOUSEX() <= SCREEN(Main,Right)

(making the same assumption that the main monitor is the one in the middle).


#5

FYI, you can change the size of the mouse point in:
System Preferences > Accessibility > Display > Cursor Size

While there, you can also check the "Increase contrast" to make reading easier.

image

Note the size of my cursor.

And here is an AppleScript to set the size:

AppleScript to Set Mouse Cursor Size

property ptyScriptName : "Set Mouse Cursor Size"
property ptyScriptVer : ".1.1"
property ptyScriptDate : "2018-01-08"
property ptyScriptAuthor : "JMichaelTX"
(*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
@SP Set the @Mouse @Cursor Size @AS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REF:
  • user3439894, How to increase cursor size programmatically?
    • Ask Different, 
  • https://apple.stackexchange.com/a/298601

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*)

### Requires Keyboard Maestro 8.0.3+ ###

set kmInst to system attribute "KMINSTANCE"

tell application "Keyboard Maestro Engine"
  set cursorSizeNum to (getvariable "Local__CursorSize" instance kmInst) as integer
end tell

if ((cursorSizeNum = "") or (cursorSizeNum = 0)) then set cursorSizeNum to 1.6

-- # set theCursorSize between 1.0 and 4 (Valid intermediate values may run out 12 decimal places.)

-- # Get the system minor version number, as an integer.

set theSystemVersion to system version of (system info)
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
set theMinorSystemVersion to text item 2 of theSystemVersion as integer
set AppleScript's text item delimiters to TID

-- # Change the size of the mouse cursor.

tell application "System Preferences"
  reveal anchor "Seeing_Display" of pane id "com.apple.preference.universalaccess"
  delay 0.1 -- # Modify as/if necessary. Value is in seconds as a decimal number.
  
  tell application "System Events"
    
    --- GET REFERENCE TO CURSOR SIZE ELEMENT BASED ON macOS ---
    
    if theMinorSystemVersion = 8 then -- macOS 10.8
      set oCursorSizeElem to value indicator 1 of slider 2 of group 1 of window "Accessibility" of application process "System Preferences"
    else if theMinorSystemVersion = 9 then -- macOS 10.9
      set oCursorSizeElem to value indicator 1 of slider 2 of window "Accessibility" of application process "System Preferences"
    else if theMinorSystemVersion ≥ 10 then -- macOS 10.10+
      set oCursorSizeElem to value indicator 1 of slider 1 of window "Accessibility" of application process "System Preferences"
    end if
    
    --- Get Current Size; Then Set New Size ---
    
    set cursorSizeOld to value of oCursorSizeElem
    set value of oCursorSizeElem to cursorSizeNum
    
  end tell -- "System Events"
  quit -- "System Preferences"
  
end tell -- "System Preferences"

set msgStr to "Cursor Size Set to " & (cursorSizeNum as text)
set msgTitleStr to ptyScriptName
--display notification msgStr with title msgTitleStr sound name "Tink.aiff"

return cursorSizeOld



#6

Thanks.
This all helps. The shake to locate and making the pointer bigger only partially help her. A cross the 3 screens it just takes her too long to even figure which screen it’s on.

What I did was have KM locate the mouse, then play the ping sound 1 time if the mouse is on monitor 1, 2 for monitor 2, etc and then locate the pointer. The audible que has her looking in the right general place so she can se the visual stimulation.

Thanks again guys


#7

Have you tried using the KM Speak Text action, to speak out loud "Mouse is on Monitor 1" (etc)?


#8

I think this should do the trick. Please let us know if this works for you and your wife.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Get Screen Number Mouse Is In and Highlight [Example]

~~~ VER: 1.0    2019-05-23 ~~~

DOWNLOAD:

Get Screen Number Mouse Is In and Highlight [Example].kmmacros (5.8 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.