Today I Learned

hashrocket A Hashrocket project

Automate Applescript via Accessibility Description

While automating a few tasks I do frequently it became apparent that many apps do not title their UI elements. This makes it more of a trial and error process to figure out which button is where.

This leads to script that is not very descriptive:

tell application "System Events"
	tell process "zoom.us"
		click button 3 of window 0
	end tell
end tell

I've always wanted to reference elements by their label or utilize accessibility attributes if they are available but could never figure out how.

I finally have!

tell application "System Events"
	tell process "zoom.us"
		click (first button where its accessibility description = "Copy Invite Link") of window 0
	end tell
end tell

This is obviously a bit more verbose but infinitly more descriptive when looking back at what a script is doing.

My future self is already thanking me.

See More #workflow TILs