AppleScript - Toggle Microphone and Video on FaceTime

Hi,
I’m trying to toggle FaceTime Microphone with AppleScript. But for some reason it won’t click am I doing it wrong?

tell application "System Events"
tell application process "Control Center"
	click menu bar item "FaceTime" of menu bar 1
	if exists (checkbox "Microphone" of window 1) then
		click checkbox "Microphone" of window 1
		perform action 1
		delay 1
	end if
end tell
key code 53 -- # escape key
end tell

Here’s a screenshot from UI Browser.

Screen Shot 2023-01-26 at 11.32.51 PM

I’m confused!

What and where is application “Control Center”?

EDIT

Found it. I don’t see a FaceTime setting anywhere in Control Center

EDIT

and what does toggling the button supposed to do. Change the input or mute or something else?

Control Center is at the top right of the menu bar.
The green FaceTime icon will show up when you start a video call.
Toggling the button changes the Mute status.

Here is the working script

tell application "System Events"
	tell application process "Control Center"
		if exists menu bar item "FaceTime" of menu bar 1 then
			click menu bar item "FaceTime" of menu bar 1
			repeat until exists scroll area 1 of window 1
				delay 0.2 -- give window time to load all items & redraw
			end repeat
			if exists (checkbox "Microphone" of window 1) then
				click checkbox "Microphone" of window 1
				delay 1
			end if
			key code 53 -- # escape key
		end if
	end tell
	beep
end tell
1 Like

This works !! Thanks.

For anyone wanting to toggle both Video and Microphone on a FaceTime call

tell application "System Events"
tell application process "Control Center"
	if exists menu bar item "FaceTime" of menu bar 1 then
		click menu bar item "FaceTime" of menu bar 1
		repeat until exists scroll area 1 of window 1
			delay 0.2 -- give window time to load all items & redraw
		end repeat
		if exists (checkbox "Microphone" of window 1) then
			click checkbox "Microphone" of window 1
			delay 1
		end if
		if exists (checkbox "Facetime Video Call" of window 1) then
			click checkbox "Facetime Video Call" of window 1
			delay 1
		end if
		key code 53 -- # escape key
	end if
end tell
beep
end tell

Would it be possible for this to work on macOS 13.2.1

Here is a version for Ventura- 13.2.x

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Events"
	tell application process "Control Center"
		set fMenu to menu bar item 1 of menu bar 1 whose description is "FaceTime"
		if exists fMenu then
			click fMenu --whose Label is "FaceTime")
			repeat until exists group 1 of window 1
				delay 0.2 -- give window time to load all items & redraw
			end repeat
			if exists (checkbox 3 of group 1 of window 1) then
				click checkbox 3 of group 1 of window 1
				delay 0.5
			end if
			if exists (checkbox 4 of group 1 of window 1) then
				click checkbox 4 of group 1 of window 1
				delay 0.5
			end if
			key code 53 -- # escape key
		end if
	end tell
	beep
end tell

and here is a version that will find the buttons by attribute name (in-case the indexes change)

tell application "System Events"
	tell application process "Control Center"
		set fMenu to menu bar item 1 of menu bar 1 whose description is "FaceTime"
		if exists fMenu then
			click fMenu --whose Label is "FaceTime")
			repeat until exists group 1 of window 1
				delay 0.2 -- give window time to load all items & redraw
			end repeat
			set cc to count checkboxes of group 1 of window 1
			set i to cc
			repeat with i from cc to 1 by -1
				if value of attribute "AXIdentifier" of checkbox i of group 1 of window 1 is "facetime-audio-input-device-toggle" then
					click checkbox i of group 1 of window 1
					delay 0.5
					exit repeat
				end if
			end repeat
			set i to cc
			repeat with i from cc to 1 by -1
				if value of attribute "AXIdentifier" of checkbox i of group 1 of window 1 is "facetime-video-device-toggle" then
					click checkbox i of group 1 of window 1
					delay 0.5
					exit repeat
				end if
			end repeat
			key code 53 -- # escape key
		end if
	end tell
	beep
end tell

OH Wait, an even more cleaned-up version:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Events"
	tell application process "Control Center"
		set fMenu to menu bar item 1 of menu bar 1 whose description is "FaceTime"
		if exists fMenu then
			click fMenu --whose Label is "FaceTime")
			repeat until exists group 1 of window 1
				delay 0.2 -- give window time to load all items & redraw
			end repeat
			set myButtons to checkboxes of group 1 of window 1 whose name of attributes contains "AXIdentifier"
			repeat with aButton in myButtons
				if (value of attribute "AXIdentifier" of aButton) is in {"facetime-audio-input-device-toggle", "facetime-video-device-toggle"} then
					click aButton
					delay 0.5
				end if
			end repeat
			key code 53 -- # escape key
		end if
	end tell
	beep
end tell

1 Like

This works, thanks for the update :pray:

How do i find all the “AXIdentifier”

If i change the button label to “close” this script wouldn’t work. This is for end call.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Events"
tell application process "Control Center"
	set fMenu to menu bar item 1 of menu bar 1 whose description is "FaceTime"
	if exists fMenu then
		click fMenu --whose Label is "FaceTime")
		repeat until exists group 1 of window 1
			delay 0.2 -- give window time to load all items & redraw
		end repeat
		set myButtons to checkboxes of group 1 of window 1 whose name of attributes contains "AXIdentifier"
		repeat with aButton in myButtons
			if (value of attribute "AXIdentifier" of aButton) is in {"close"} then
				click aButton
				delay 0.5
			end if
		end repeat
		key code 53 -- # escape key
	end if
end tell
beep
end tell

@robertfern, the above script no longer works in macOS Sonoma 14.3.1. If you are using the latest could you please update the script. Thanks