Set cliclick co-ordinates relevant to UI element in AppleScript

633 views Asked by At

Firstly I have only been using AppleScript for the last couple of days, so am really new to it and have no real other scripting knowledge, so forgive me if this comes across as something trivial or I ask lots of follow up questions.

I have an element that I would like to right click on using cliclick, but the location of the element moves depending upon other windows and sidebars being open

I would like to use

position of button 1

to return the correct co-ordinates so I would like to be able to use maths to add to the X,Y co-ordinates in cliclick so it would be something like this

position of button 1
do shell script "../cliclick c:x+25,y+5"

is this possible or is it something that I will have to using another language? I am thinking the final project will be compiled into an application using Xcode and will be hiring someone for this, am just trying to make their life as easy as possible beforehand.

2

There are 2 answers

0
SemPath On

A more compact equivalent code:

set {x, y} to position of button 1 of toolbar 1 of toolbar 3 of window 1
do shell script "/Users/dave/_app-dev/cliclick c:" & x & "," & y & ""
0
DaveClissold On

Ok after a bit of fumbling around the internet I found something else and then fiddled with it a bit and finally solved the above using the following

        tell UI element 1 of toolbar 1 of toolbar 3 of the front window
            set p to position
            set x to item 1 of p
            set y to item 2 of p
        end tell

do shell script "/Users/dave/_app-dev/cliclick c:" & x & "," & y & ""

Just incase anyone else looks for it here is the answer