BlueM / cliclick

macOS CLI tool for emulating mouse and keyboard events
https://www.bluem.net
Other
1.59k stars 116 forks source link

Support coordinates from right and bottom #133

Open gingerbeardman opened 2 years ago

gingerbeardman commented 2 years ago

It would be great to be able to specify co-ordinates from the right and bottom of the screen as well as the top and left.

This way, I can make sure my script that clicks something in the top right corner works on monitors of all sizes.

Currently my options seem to be

BlueM commented 2 years ago

There is another option: ask the system for the screen size.

osascript -e 'tell application "Finder" to get bounds of window of desktop' 

… will return X1, Y1, X2, Y2. So the top right corner could be clicked (written as a one-line) using …

cliclick -e 200 c:$( osascript -e 'tell application "Finder" to get bounds of window of desktop' | awk '{ print $3 }')0
gingerbeardman commented 2 years ago

Love it!

For anybody else, this line:

osascript -e 'tell application "Finder" to get bounds of window of desktop' | awk '{ print $3 }'

returns: 1080, (for my display)

...so the line ends 0 rather than ,0

BlueM commented 2 years ago

Just for the record: the awk invocation is just one example of splitting the result. A “cleaner” one would be …

osascript -e 'tell app "Finder" to get bounds of window of desktop' | cut -d ',' -f3 | xargs echo -n

… which will result in a plain number without comma. Or the AppleScriptish way:

osascript -e 'tell app "Finder" to set d to bounds of window of desktop' -e 'item 3 of d'