While in Eugene this weekend setting up some art in a gallery installation, I found myself writing a piece of applescript to load a video, loop it, and place it in full screen whenever the computer booted up.
Then I encountered a small problem: when it loaded, the computer was placing the mouse cursor in the upper left corner of the screen, keeping the file menu visible, despite the full screen video.
Not wanting to make extra work for the gallery manager, I decided to solve the problem through applescript.
Now, there is not a direct command in applescript to control the mouse (which is a bummer, as that would have been incredibly easy.) but there is a way to emulate keystrokes. This is enough.
By enabling universal accessibility we can use key strokes to move the mouse.
To enable universal accessibility:
- First, open up your system preferences, and go to “Universal Access.”
- Next, go to “Mouse & Trackpad.”
- Finally, turn on Mouse Keys.
Mouse keys allow you to use the number pad of the keyboard in place of a mouse.
Numpad 5 is click, and the numbers around it correspond to direction (2 down, 6 right, 3 down-right, and so on)
Once Mouse Keys are enabled, in applescript we can say
tell application “System Events” to key code ##
with ## being replaced with the corresponding integer value of the key code (which you can determine using Full Key Codes) and it will move the cursor roughly 1 pixel in that direction.
Repeat that line a bunch of times, and you can ensure that your cursor won’t be in the top corner of the screen.