3

I'm trying to automate the running of techtools via AppleScript. I have got it working but only with full keyboard access (using tab and space to navigate the UI) but not all machines have this enabled when I first turn them on so I need a way of activating the run check computer.
I assume this is possible with the "click button" function but I cannot work out how to find out which button is which with accessibility inspector. Here is the layout of TechTools and you can see in the bottom left is the button I want to press to start the tests.

TechTools run check computer button

And here is the inspector info on the button.
enter image description here

As I said, I can activate this fine when full keyboard access is enabled because it's just a case of copying keyboard strokes.

I'm not sure if i'm misunderstanding the concept of identifying the buttons within the program or how to specify which window it's in (I assume it's window 1.)

This is an example of the type of script I've been writing to attempt to achieve this (I know this one just minimises the window.) Do I keep increasing the value of the button until it eventually just runs check computer? When I tried button 4 it activated an option under File on the top bar.
Any help would be greatly appreciated.

tell application "System Events"
    tell process "TechTool Pro 9"
        click button 2 of window 1
    end tell
end tell
  • 1
    If you look at the Hierarchy in the Inspector window, it shows the Run Check Computer button inside of a group. So, you'd have to use something like e.g.: click button 2 of group 1 of window 1 – user3439894 Jun 25 '18 at 14:04
  • 1
    This actually makes a lot of sense and I think this will lead to the correct code but when trying different groups it throws up an invalid index error message. Should there be a number identifier for groups or is it a case of just guessing until something clicks? – wolfiejoe Jun 25 '18 at 14:16
  • 2
    First of all, UI Scripting can be messy and problematic and does not work well in all cases. Personally, I try to say away from UI Scripting if there are other alternatives. I do not have TechTool to do any testing and why I just left a comment. If you do a little googling, you can see how to get the underlying AppleScript code from an Automator Watch Me do action, which may help you to get the correct UI Scripting code to accomplish your task. – user3439894 Jun 25 '18 at 15:03
  • Do you think Automator could fulfil what I'm trying to do but better then? I'm willing to use that instead as long as it's just a case of double click and application/script and then it taking care of the rest for me. And it also has to work on fresh machines where the only thing that has happened to them is the root user has been enabled and a usb has been plugged in. – wolfiejoe Jun 25 '18 at 15:10
  • 1
    No, the Automator suggestion was basically another little trick to obtain the object reference. There's an action called Watch Me Do, which records your mouse clicks and returns some AppleScript code containing the object referencing. It's a similar technique to mine, but slightly differently implemented. You could try using that to see if it can pick up the object reference. – CJK Jun 25 '18 at 15:43
3

Here's a little trick:

Obtain the screen coordinates of that button. You can do this by initiating a screen capture with crosshairs, usually by pressing 4 (⟨Cmd⟩⟨Shift⟩⟨4⟩). Navigate the cross hairs over the button within its clickable region.

I did a similar thing with a dialog box in Script Editor:

Crosshairs in macOS

You can just about make out the coordinates of my button are {896,674}.

Next, in Script Editor, enter this line of code, inserting your coordinates as appropriate:

    tell application "System Events" to click at {896, 674}

I can assume you already have the right accessibility privileges granted from the context of your post. Therefore, you can simply run this script.

Just ensure the button is visible before you run the script, and that it hasn't changed position on the screen. Make sure there are no windows obscuring or overlying it.

All being well, two things will happen:

  1. The system will issue a click and it'll click that button;
  2. In the results pane at the bottom of the Script Editor window, you'll see something like this:
    button "Done" of window "Open" of application process "Script Editor" of application "System Events"

That is the reference to the button object, which you can copy and paste into your script.

It works for any GUI item on the screen: just isolate its coordinates, issue a click, and it will return the object reference.

UPDATE:

Having just acquired a copy of TechTool Pro version 8, I have learned that the application is not GUI-scriptable. Therefore, this explains why the trick I described failed to return an object reference (because there is none), and unfortunately, you won't be able to automate the running of TechTools using AppleScript.

  • 1
    I like the idea of this, it sounds solid. My only issue is would this still work across all the different resolutions from the old white macbooks to the 5k iMacs and iMac Pros? – wolfiejoe Jun 25 '18 at 15:12
  • 1
    Yes, the resolutions are irrelevant. You're only obtaining the coordinates once, and utilising the line of code once. After you get the reference to your GUI object, you don't need that other line of code or the coordinates at all. You'll be using the object reference. Does this make sense ? – CJK Jun 25 '18 at 15:17
  • 1
    The code does work; I tried it in a finder window as a test and it outputted fine. I'm worried now that the UI for techtools has a lack of compatibility with this and may not work. I'll keep trying to find a part of the button that works. – wolfiejoe Jun 25 '18 at 15:26
  • 1
    Please see the update at the bottom of my answer. It's bad news, I'm afraid. – CJK Jun 25 '18 at 16:12
  • 1
    It only outputs the traffic light buttons... I think that says that techtool does not have compatibility for this task :( – wolfiejoe Jun 25 '18 at 16:14
1

Sikuli

While this is possible with AppleScript, consider using Sikuli for this task:

Sikuli automates anything you see on the screen. It uses image recognition to identify and control GUI components. It is useful when there is no easy access to a GUI's internal or source code.

  • So I can write a script with this software and run it on a fresh installed OS with a simple double click? – wolfiejoe Jun 25 '18 at 16:21
  • I believe you can run it from another computer and then use built-in screen sharing to remote control the freshly installed macOS. – Graham Miln Jun 25 '18 at 16:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .