Ce n'est pas aussi élégant que je l'espérais, mais cela semble fonctionner.
Après avoir joué avec la fonction d'enregistrement pendant un certain temps, il semble que je puisse activer le DND lorsqu'il est désactivé :
-- 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
et vice versa :
-- 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
Il serait préférable qu'il existe une solution qui vérifie son état ou qui spécifie explicitement le nouvel état souhaité au lieu de simplement basculer. Il y a une petite différence entre les scripts, ce n'est donc pas un problème. exactement mais il fonctionne en cliquant sur le bouton.