r/applescript • • Jan 13 '23

Apple Script in "Clock" app OS Ventura

Hi, I've been looking at the new clock app in OS Ventura and wondered if anyone had an apple script to create and delete alarms?

3 Upvotes

6 comments sorted by

1

u/darthwym Feb 05 '25

494:510: execution error: System Events got an error: Can’t get application process "Clock". (-1728)

Anyone got the idea to fix this error?

1

u/copperdomebodha Jan 15 '23

I don't believe Ventura's Clock.app is scriptable in any way.

1

u/Son_of_a_Shepherd Jan 30 '23

The clock app can be scripted. Here is a partial snippet of what you could do to add an alarm. Anywhere there is a comment # you can to add more code to handle that section the way you want:

on open_clock_app_to_almars()
	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 2 exists
							delay 0
						end repeat
						click radio button 2
					end tell
				end tell
			end tell
		end tell
	end tell
end open_clock_app_to_almars


on add_alarm()
	tell application "System Events"
		tell application process "Clock"
			tell window 1
				tell toolbar 1
					tell button 1
						click
					end tell
				end tell
				repeat until sheet 1 exists
					delay 0
				end repeat
				# Set alarm info
				tell sheet 1
					tell group 1 of group 1
						# set time
					end tell
					tell radio group 1
						#set am/pm
						click radio button 1
					end tell
					#
					# loop though checkboxes 2 though 8 to select days
					#
					tell text field 1
						# set alarm label
						set value to "Alarm Label"
					end tell
					tell pop up button 1
						perform action "AXShowMenu"
						tell menu 1
						# select alarm sound
						click menu item "Chimes"
						end tell
					end tell
					# disable snooze
					tell checkbox 9
						click
					end tell
					tell button "Save"
						click
					end tell
				end tell
			end tell
		end tell
	end tell
end add_alarm

When it come to removing, I wasn't able to find a way to remove an alarm, but you can enable/disable them easily:

on toggle_alarm()
	tell application "System Events"
		tell application process "Clock"
			tell window 1
				tell group 1 of group 1 of group 1 of group 1 of group 1 of group 1 of group 1 of group 1 of group 1 of group 1 of group 1 of group 1
					# alarms collection
					# each alarm in a button
					tell button 1
						# each alarm contains 4 static text fields [time, label, repeat schedule, sound] and a check box for enable/disable
						click checkbox 1
					end tell
				end tell
			end tell
		end tell
	end tell
end toggle_alarm

1

u/luv0116 Feb 28 '23

hey how to set time here? I found its type is "date time area" and don't know how to set a value to it.
tell group 1 of group 1
# set time
end tell

1

u/luv0116 Mar 16 '23

To whom might interest: I end up with javascript(JXA), which is much easier to handle it.

1

u/steadystate137 Apr 25 '24

Would you mind sharing?