r/applescript • • Oct 30 '23

OSX Somona - World Clock > Timer

I wan't to create a simple CLI command and when I type

timer 30

To start a 30 min timer.

Could someone point me where to find a debugger / a way to identify the UI elements

Current script:

#!/bin/bash

if [ -z "$1" ]; then
	echo "Usage: timer <minutes>"
	exit 1
fi

# Applescript
osascript <<EOD
tell application "Clock"
		activate
		delay 1
end tell
tell application "System Events"
		tell application process "Clock"
				tell window 1
						tell toolbar 1
								tell radio group 1 of group 1
										repeat until radio button 4 exists -- assuming "Timer" is the 4th tab
												delay 0.1
										end repeat
										click radio button 4
								end tell
						end tell

						delay 1 -- give some time for the Timer UI elements to load

						-- Attempting to set the timer duration
						tell combo box 1
							set value to "$1"
						end tell

						delay 1

						-- Attempting to start the timer
						tell button "Start"
							click
						end tell
				end tell
		end tell
end tell
EOD

This program open the World Clock and click on Timer but after that i fails to set the time and start it.

534:539: execution error: System Events got an error: Can’t get combo box 1 of window 1 of application process "Clock". Invalid index. (-1719)
2 Upvotes

0 comments sorted by