I’m using Keyboard Maestro to run a script to click the menu bar to Pause/Resume Google Drive’s sync, but sometimes I get an error and I would like to know if I can use AS to check if a certain GUI element in the menu bar is visible/available?
Right now I have a script, but sometimes it throws me an error like this (this is KM’s log):
Execute an AppleScript failed with script error: text-script:114:207: execution error: System Events got an error: Can’t get group 3 of UI element 1 of window 1 of process "Google Drive". Invalid index. (-1719)
So I’m assuming it’s because it’s not being fast enough. I could increase the delay, but I was wondering if I could pause the macro and wait for each element to be visible or available?
Here’s the script
tell application "System Events"
tell process "Google Drive"
click menu bar item 1 of menu bar 1
delay 0.2
click pop up button 1 of group 1 of group 1 of group 1 of group 3 of UI element 1 of window 1
delay 0.2
click menu item 4 of menu 1 of group 1 of group 2 of group 1 of group 3 of group 1 of UI element 1 of window 1
delay 0.2
click menu bar item 1 of menu bar 1
end tell
end tell
For example this is the icon:
![](https://www.macscripter.net/uploads/default/original/2X/f/fe34288c3b50d311086fdc559b66815fb14cdef5.png)
Then when the window opens up, this is the icon I need to click:
![](https://www.macscripter.net/uploads/default/original/2X/4/476c31d47b94732d22baeeb8cda28da4f37c234b.png)
Then after that, I click the Resume syncing / Pause syncing
I found this topic, tested the script using Safari and it indeed showed me a list of elements:
Script:
tell application "System Events"
tell process "Safari"
set visible to true
return every UI element of front window
return name of every UI element of front window
end tell
end tell
So I would guess that the menu bar can also be scanned and check if element XYZ is visible or not?