AppleScript Do Not Disturb on Mac?

I had the same problem. Therefore I included the System Shortcut in my AppleScripts:

When starting my AppleScripts a popup window appears in which I can enter the duration of the DND:

DND only:

tell application “System Events”

keystroke “d” using { command down , option down , control down , shift down }

end tell

set theTime to text returned of ¬

( display dialog (“How long should it remain activated?”) ¬

with title (“Do not Disturb”) ¬

default answer (“”) ¬

buttons {“Cancel”, “Start”} ¬

default button 2)

delay theTime * 60

tell application “System Events”

keystroke “d” using { command down , option down , control down , shift down }

delay 0.4

display notification “Is deactivated” with title “Do not Disturb” sound name “Tink”

end tell

DND & Sound:

tell application “System Events”

keystroke “d” using { command down , option down , control down , shift down }

set volume with output muted – mute volume

end tell

set theTime to text returned of ¬

( display dialog (“How long should it remain activated?”) ¬

with title (“Do not Disturb”) ¬

default answer (“”) ¬

buttons {“Cancel”, “Start”} ¬

default button 2)

delay theTime * 60

set volume without output muted – unmute volume

tell application “System Events”

keystroke “d” using { command down , option down , control down , shift down }

delay 0.4

display notification “Is deactivated” with title “Do not Disturb” sound name “Tink”

end tell

DND, Sound & Items:

tell application “System Events”

keystroke “d” using { command down , option down , control down , shift down }

set volume with output muted – mute volume

do shell script "defaults write com.apple.finder " & ¬

"CreateDesktop -bool false; " & ¬

“killall Finder” – hide desktop icons

end tell

set theTime to text returned of ¬

( display dialog (“How long should it remain activated?”) ¬

with title (“Do not Disturb”) ¬

default answer (“”) ¬

buttons {“Cancel”, “Start”} ¬

default button 2)

delay theTime * 60

tell application “System Events”

keystroke “d” using { command down , option down , control down , shift down }

set volume without output muted – unmute volume

do shell script "defaults write com.apple.finder " & ¬

"CreateDesktop -bool true; " & ¬

“killall Finder” – unhide desktop icons

delay 0.8

display notification “Is deactivated” with title “Do not Disturb” sound name “Tink”

end tell