Skip to main content
updated dead link. copied in content from reference link to get above 6 character limit
Source Link

You can simplify the answer that razvanz provided by using the -currentHost argument to the defaults command.

Enable Do Not Disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +0000\"`"
killall NotificationCenter

(via https://heyfocus.com/enabling-do-not-disturb-mode/https://heyfocus.com/blog/enabling-do-not-disturb-mode/)

Disable Do Not Disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
killall NotificationCenter

Now you could easily wrap this up as a script to enable or disable Do"Do Not DisturbDisturb" as a script that would work on anybody's machine regardless of system preferences. Here is an example of how to do that:

#!/bin/bash

set -eou pipefail

# From https://heyfocus.com/enabling-do-not-disturb-mode and
# https://apple.stackexchange.com/questions/145487

if [[ $(defaults -currentHost read ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb) -eq 0 ]]; then
  defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
  defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +000\"`"
  killall NotificationCenter
  echo "Do Not Disturb is enabled. Run $0 to turn it off (OS X will turn it off automatically tomorrow)."
else
  defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
  killall NotificationCenter
  echo "Do Not Disturb is disabled. Run $0 to turn it on again."
fi

Source: https://gist.github.com/ryangreenberg/5267f68a8e7b07ea66370b4eb5580ab9

You can simplify the answer that razvanz provided by using the -currentHost argument to the defaults command.

Enable Do Not Disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +0000\"`"
killall NotificationCenter

(via https://heyfocus.com/enabling-do-not-disturb-mode/)

Disable Do Not Disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
killall NotificationCenter

Now you could easily wrap this up as a script to enable or disable Do Not Disturb as a script that would work on anybody's machine regardless of system preferences. Here is an example of how to do that: https://gist.github.com/ryangreenberg/5267f68a8e7b07ea66370b4eb5580ab9

You can simplify the answer that razvanz provided by using the -currentHost argument to the defaults command.

Enable Do Not Disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +0000\"`"
killall NotificationCenter

(via https://heyfocus.com/blog/enabling-do-not-disturb-mode/)

Disable Do Not Disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
killall NotificationCenter

Now you could easily wrap this up as a script to enable or disable "Do Not Disturb" as a script that would work on anybody's machine regardless of system preferences. Here is an example of how to do that:

#!/bin/bash

set -eou pipefail

# From https://heyfocus.com/enabling-do-not-disturb-mode and
# https://apple.stackexchange.com/questions/145487

if [[ $(defaults -currentHost read ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb) -eq 0 ]]; then
  defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
  defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +000\"`"
  killall NotificationCenter
  echo "Do Not Disturb is enabled. Run $0 to turn it off (OS X will turn it off automatically tomorrow)."
else
  defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
  killall NotificationCenter
  echo "Do Not Disturb is disabled. Run $0 to turn it on again."
fi

Source: https://gist.github.com/ryangreenberg/5267f68a8e7b07ea66370b4eb5580ab9

link to source rather than just to user profile, fix block code formatting, quote formatting for quoted content
Source Link
grg
  • 205.6k
  • 45
  • 364
  • 496

You can simplify the answer that razvanz providedthe answer that razvanz provided by using the -currentHost argument to the defaults command.

Enable do-not-disturbDo Not Disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +0000\"`"
killall NotificationCenter

(via https://heyfocus.com/enabling-do-not-disturb-mode/)

Disable do-not-disturbDo Not Disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
killall NotificationCenter

Now you could easily wrap this up as a script to enable or disable do-not-disturbDo Not Disturb as a script that would work on anybody's machine regardless of system preferences. Here is an example of how to do that: https://gist.github.com/ryangreenberg/5267f68a8e7b07ea66370b4eb5580ab9

You can simplify the answer that razvanz provided by using the -currentHost argument to the defaults command.

Enable do-not-disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +0000\"`"
killall NotificationCenter

(via https://heyfocus.com/enabling-do-not-disturb-mode/)

Disable do-not-disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
killall NotificationCenter

Now you could easily wrap this up as a script to enable or disable do-not-disturb as a script that would work on anybody's machine regardless of system preferences. Here is an example of how to do that: https://gist.github.com/ryangreenberg/5267f68a8e7b07ea66370b4eb5580ab9

You can simplify the answer that razvanz provided by using the -currentHost argument to the defaults command.

Enable Do Not Disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +0000\"`"
killall NotificationCenter

(via https://heyfocus.com/enabling-do-not-disturb-mode/)

Disable Do Not Disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
killall NotificationCenter

Now you could easily wrap this up as a script to enable or disable Do Not Disturb as a script that would work on anybody's machine regardless of system preferences. Here is an example of how to do that: https://gist.github.com/ryangreenberg/5267f68a8e7b07ea66370b4eb5580ab9

added 109 characters in body
Source Link
Ryan
  • 331
  • 2
  • 4

You can simplify the answer that razvanz provided by using the -currentHost argument to the defaults command.

Enable do-not-disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +0000\"`"
killall NotificationCenter

(via https://heyfocus.com/enabling-do-not-disturb-mode/)

Disable do-not-disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
killall NotificationCenter

Now you could easily wrap this up as a script to enable or disable do-not-disturb as a script that would work on anybody's machine regardless of system preferences. Here is an example of how to do that: https://gist.github.com/ryangreenberg/5267f68a8e7b07ea66370b4eb5580ab9

You can simplify the answer that razvanz provided by using the -currentHost argument to the defaults command.

Enable do-not-disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +0000\"`"
killall NotificationCenter

(via https://heyfocus.com/enabling-do-not-disturb-mode/)

Disable do-not-disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
killall NotificationCenter

Now you could easily wrap this up as a script to enable or disable do-not-disturb as a script that would work on anybody's machine regardless of system preferences.

You can simplify the answer that razvanz provided by using the -currentHost argument to the defaults command.

Enable do-not-disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean true
defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturbDate -date "`date -u +\"%Y-%m-%d %H:%M:%S +0000\"`"
killall NotificationCenter

(via https://heyfocus.com/enabling-do-not-disturb-mode/)

Disable do-not-disturb:

defaults -currentHost write ~/Library/Preferences/ByHost/com.apple.notificationcenterui doNotDisturb -boolean false
killall NotificationCenter

Now you could easily wrap this up as a script to enable or disable do-not-disturb as a script that would work on anybody's machine regardless of system preferences. Here is an example of how to do that: https://gist.github.com/ryangreenberg/5267f68a8e7b07ea66370b4eb5580ab9

Source Link
Ryan
  • 331
  • 2
  • 4
Loading