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
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.
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
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
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
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