No es tan elegante como esperaba, pero parece que funciona.
Después de jugar un rato con la función de grabación, parece que puedo activar el DND cuando está apagado:
-- Click the “Notification Center” menu bar item.
delay 1.109957
set timeoutSeconds to 0.0
set uiScript to "click menu bar item \"Notification Center\" of menu bar 1 of application process \"SystemUIServer\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “<fill in title>” button.
delay 2.096055
set timeoutSeconds to 0.0
set uiScript to "click UI Element 3 of group \"Do Not Disturb\" of scroll area 1 of window \"Notification Center\" of application process \"Notification Center\""
my doWithTimeout(uiScript, timeoutSeconds)
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
try
run script "tell application \"System Events\"
" & uiScript & "
end tell"
exit repeat
on error errorMessage
if ((current date) > endDate) then
error "Can not " & uiScript
end if
end try
end repeat
end doWithTimeout
y viceversa:
-- Click the “Notification Center” menu bar item.
delay 2.508349
set timeoutSeconds to 2.0
set uiScript to "click menu bar item \"Notification Center, Do Not Disturb enabled\" of menu bar 1 of application process \"SystemUIServer\""
my doWithTimeout(uiScript, timeoutSeconds)
-- Click the “<fill in title>” button.
delay 1.176098
set timeoutSeconds to 2.0
set uiScript to "click UI Element 3 of group \"Do Not Disturb\" of scroll area 1 of window \"Notification Center\" of application process \"Notification Center\""
my doWithTimeout(uiScript, timeoutSeconds)
on doWithTimeout(uiScript, timeoutSeconds)
set endDate to (current date) + timeoutSeconds
repeat
try
run script "tell application \"System Events\"
" & uiScript & "
end tell"
exit repeat
on error errorMessage
if ((current date) > endDate) then
error "Can not " & uiScript
end if
end try
end repeat
end doWithTimeout
Sería mejor si hubiera una solución que comprobara su estado o especificara explícitamente el nuevo estado deseado en lugar de limitarse a alternar. Hay una pequeña diferencia entre el "on" y el "off" scripts así que no es exactamente pero funciona pulsando el botón.